Will I fire a change event if I use Javascript to set <option> as the selected one?

I noticed that in Google Chrome, the <option> setting selected with Javascript does not trigger the corresponding <select> tag change event.

Can I assume that this behavior is true in all other modern browsers?

+4
source share
4 answers

Setting an option selected using JavaScript or selecting an option by focusing, and then using the up and down buttons to select it, is not accepted as an event by the onchange() event handler, as can be seen from the following links:




PS: A similar situation arose when I tried to call <element onmousedown="doStuff();"> by calling element.click();

+1
source

Setting any value for any field in JavaScript should not trigger any events.

If they did, you would end up in an endless cycle of events.

If you want, you can manually trigger the change event.

+1
source

Yes, that must be true. In my experience, this works in IE 6, Chrome, FF, and Safari. I would agree that testing in all browsers that you intend to support is reasonable!

0
source

option: selected yes it works I just used it myself. Even supported in IE 6 - IE 8 webkit and FF

0
source

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


All Articles