Is there a way for an HTML select element to call a function every time its selection has been changed programmatically?
Both IE and FF will not trigger "onchange" when the current selection in the select box is changed using javascript. In addition, the js function, which changes the selection, is part of the framework, so I cannot change it to call, for example, onchange (), for example, at the end.
Here is an example:
<body> <p> <select id="sel1" onchange="myfunction();"><option value="v1">n1</option></select> <input type="button" onclick="test();" value="Add an option and select it." /> </p> <script type="text/javascript"> var inc = 1; var sel = document.getElementById('sel1'); function test() { inc++; var o = new Option('n'+inc, inc); sel.options[sel.options.length] = o; o.selected = true; sel.selectedIndex = sel.options.length - 1; } function myfunction() { document.title += '[CHANGED]'; } </script> </body>
Is there a way to make test () call myfunction () without changing test () (or adding an event to a button)?
Thanks.
javascript html events html-select
Goffer
source share