tags:

views:

92

answers:

3

I have a standard html drop down box.

I want to run js code after the user selected an item without a separate submit button.

Onchange event does not fire when the user selects the 1st item (actually the previously selected item) in the select box.

How can I make the combo box react to the click even if the previously selected item is clicked?

Notes: 1. I don't want to add 'select from here' or something similar to the select box. 2. the onclick event does not help since it fires also on the 1st click the user does to open the options before actually selecting one.

+1  A: 

I don't think this can't be done. onchange, as you correctly point out, doesn't work. onmouseup fires too early.

I think onblur would do the trick but it will also fire when the user tabs through the available elements.

If you really need this to work reliably, consider using a JavaScript based replacement widget like this one. They enable you to work around the notorious lack of flexibility that standard form elements unfortunately have.

Oh and by the way, the <select> element is not a combo box, it's a drop-down.

:)

Pekka
+1  A: 

You can use the onclick event but at the same time count the number of clicks.

  <script type="text/javascript">
      var count = 0;

      function selectClicked(sel){
            count++;
            if (count == 2){
               //the user has selected something
               //so go ahead and handle it
               count = 0; 
            }
      }

  </script>
Vincent Ramdhanie
+1  A: 

What if you added the "onclick" event to the individual "option" elements rather than the "select" element?

attack
excellent! it works. Thanks
Nir
But does it work in IE *and* FF *and* Safari? I'm not sure.
Pekka
unfortunately it doesnt work on safari and chrome.... need another solution
Nir