This doesn't seem to be working:
<select id="mySel" onchange="alert('foo')">
<option value="a">a</option>
<option value="b">b</option>
</select>
<script>
dojo.byId('mySel').value = 'b'; // select changes, but nothing is alerted
</script>
(I'm using dojo, but that doesn't really matter.)
The 'onchange' name is a little misleading unless you understand that a change event and a value being changed aren't the same thing. A change event occurs when the user changes the value in the browser. I believe you can fire the event manually by calling dojo.byId('mySel').onchange()
after you programmatically change the value, though. (You might need to actually define a function that calls alert
, though. I haven't done this myself.)
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