Programmatically firing an HTML select element onchange event

How can I fire the onchange event of an HTML Select element by code.

The next item selects only the list item, but doesn't seem to fire the onchange event?

options[index].selected = true; 
+4
source share
1 answer

If the event is called directly through onchange , you can call the handler by calling this handler, for example:

 mySelect.options[index].selected = true; mySelect.onchange(); 

... if it does not adjust in this way, then different approaches are appropriate depending on how you are attached, and more information on how your handlers are bound (t)> onchange .

+8
source

Source: https://habr.com/ru/post/1334017/


All Articles