I’m trying to trigger a second event dependent on the first like so:
...
$('#productFamilyId').val(data.contents.productfamily);
$('#productFamilyId').trigger('change', function() {
$('#productId').val(data.contents.product);
$('#productId').trigger('change');
});
It’s not waiting for the first trigger to complete before attempting to trigger the second event. Is it possible to wait for the first trigger to complete?
There is no callback for the trigger method. The extra parameters are just that – parameters.
http://api.jquery.com/trigger/
What you’re actually doing is running the code in the second function and then passing the result as a parameter into the event handler called by trigger. You need to trigger the 2nd event within the event handler for the first event if you want them to run in sequence.