I have an HTML select dropdown whose value may be edited programmatically. My change event fires when the user edits the value from the page, but not when the value is changed in the code. I need the event to fire in both cases. Any ideas on how to accomplish this?
$("#dropdownId").on('change', function () {
//do stuff
});
...
var df = document.frmMain;
df.dropdownId.value = someValue; //change event does not fire
You can use jQuery's .trigger
to fire an event. In your case:
$("#dropdownId").trigger("change");
You need to manually fire the event using jquery trigger function after settig the value :
$("#dropdownId").trigger('change');
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