How can I fire the onchange event of an HTML Select element by code.
The following only selects a list item but doesn't seem to fire the onchange event?
options[index].selected = true;
If the event is hoked up directly via onchange
, you can invoke the handler by calling that handler, like this:
mySelect.options[index].selected = true;
mySelect.onchange();
...if it's not rigged up that way, then different approaches are appropriate depending on how you're binding, and more information about how your onchange
handler(s) are attached would help.
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