If your event handler does not make an asynchronous call , the triggered event will be executed and finished, and then go to the next line. Jsfiddle
$('#productFamilyId').val(data.contents.productfamily); $('#productFamilyId').trigger('change'); // Execute after change complete $('#productId').val(data.contents.product); $('#productId').trigger('change');
With an asynchronous call (setTimeOut, Ajax, etc.) in the event handler, you can do this: JsFiddle
Add a callback function as a parameter in the event handler:
$("#productFamilyId").change(function(e, callback) {
And run as follows:
$('#productFamilyId').trigger('change', function() { $('#productId').val(data.contents.product); $('#productId').trigger('change'); });
source share