How to cancel change event for combo box (SELECT) element. There is no onbefore or onchanging event for HTML SELECT element. If I put:
<SELECT onchange="return false;">
<OPTION value=a>A</OPTION>
<OPTION value=b>B</OPTION>
</SELECT>
event is not canceled.
You need to save the original value of the
<select>somewhere. So that you can change the value back.Cancelling the event, only does that. It just cancels the event, it doesn’t change the value.
Example (using jQuery):
DEMO: http://jsfiddle.net/pL2B4/
Pure JavaScript solution (no jQuery):
DEMO: http://jsfiddle.net/pL2B4/1/