I have the following markup:
<select onchange="jsFunction()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
When a user pulls down the combobox and selects the same option that was previously selected (or doesn't change the selection at all), JavaScript doesn't regard it as an onchange
event. So, the jsFunction()
is not called. But I want the jsFunction()
called even in this case. How can I achieve this?
use the "onmouseup" property with each option element. it's verbose, but should work. also, depending on what your function is actually doing, you could arrange things a little differently, assuming the number is important in the handler:
Just set the
selectIndex
of the associated<select>
tag to-1
as the last step of your processing event.It works every time, removing the highlight and allowing you to select the same (or different) element again .
I'd do it like this:
If you want you could have the same label as the first option, which in this case is 1. Even better: put a label in there for the choices in the box.
You have to add empty option to solve it,
I also can give you one more solution but its up to you that is fine for you or not Because User select default option after selecting other options than jsFunction will be called twice.
JavaScript code:
The only drawback is that when the user clicks on the dropdown list, the currently selected item does not appear selected
It's not firing because the value hasn't "changed". It's the same value. Unfortunately, you can't achieve the desired behaviour using the
change
event.You can handle the
blur
event and do whatever processing you need when the user leaves the select box. That way you can run the code you need even if the user selects the same value.