I have an input form that lets me select from multiple options, and do something when the user changes the selection. Eg,
<select onChange="javascript:doSomething();">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
Now, doSomething()
only gets triggered when the selection changes.
I want to trigger doSomething()
when the user selects any option, possibly the same one again.
I have tried using an "onClick" handler, but that gets triggered before the user starts the selection process.
So, is there a way to trigger a function on every select by the user?
Update:
The answer suggested by Darryl seemed to work, but it doesn't work consistently. Sometimes the event gets triggered as soon as user clicks the drop-down menu, even before the user has finished the selection process!
So my goal was to be able to select the same value multiple times which essentially overwrites the the onchange() function and turn it into a useful onclick() method.
Based on the suggestions above I came up with this which works for me.
http://jsfiddle.net/dR9tH/19/
first of all u use onChange as an event handler and then use flag variable to make it do the function u want every time u make a change
What I did when faced with a similar Problem is I added an 'onFocus' to the select box which appends a new generic option ('select an option'or something similar) and default it as the selected option.
A long while ago now but in reply to the original question, would this help ? Just put
onClick
into theSELECT
line. Then put what you want eachOPTION
to do in theOPTION
lines. ie:what about changing the value of the select when the element gains focus, e.g (with jquery):