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;
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;
Share
Improve this question
asked Jan 3, 2011 at 0:22
TermanTerman
9835 gold badges17 silver badges24 bronze badges
1 Answer
Reset to default 8If 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.