I would like to be able to detect when the selected value of dropdown has changed using jQuery. The selected value of the dropdown is changed by other JavaScript, so I want to be able to catch this event.
I can see the dropdown changing, however the following code does not capture the event correctly. Does the change event only capture the event when it is performed by the user and not other code?
$('select[name=b_country]').live('change', function() {
alert('the country dropdown has changed');
});
<select name="b_country" style="display: block;">
Yes, only user interactions fire the event. Otherwise you wouldn’t be able to (re)set values in a listener without entering an infinite loop.
If you want to inform other (listening) scripts that you changed the value, you can manually trigger an event. With jQuery, this is easy: