I have a select, and I need to fire some js each time an option is selected, even if it is already selected. Example:
<select id="select_one">
<option value="">Choose One...</option
<option value="one">One</option>
<option value="two">Two</option>
</select>
If someone selects "one" I want to fire functionOne(). But, while "one" is selected, if the user selects "one" again I want to fire functionOne() again. So, that means onChange won't work, since the selection isn't changing.
Anyone have any thoughts?
Contrary to some of the current answers, you don't actually get a click event on <option> in IE.
The only reliable way to detect the case of an option being clicked that was already selected is to put the onclick handler on the <select>. Naturally this will also detect any other clicks on the select element, so depending on what functionOne() is doing this may not be safe either.
You might be better off with something that looks like a select but isn't, such as a pop-up div with buttons on it. What is it you are trying to do? If you're trying to do a “jump menu” where selecting an option navigates to a new page: don't, it's an old and discredited mechanism with serious usability problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With