Serjas
Serjas

Reputation: 2284

trigger 'click' after selected an option?

I have select box which load addresses form via ajax. So user can select previous saved address. Inside address form , another select box which lists 'States'. A shipping is calculated based on 'States' select box change.

I want to trigger a change after loading addresses. I used this code

$('select#addressed').change(function() {      
  $('select#states').trigger('change');
});

But this will trigger change before new address load.Any way to trigger after loading address?

Upvotes: 1

Views: 405

Answers (2)

Yatrix
Yatrix

Reputation: 13795

Fire the change in the success section of the Ajax call. That way it won't fire until the data comes back. You could also use a $.when/.done as well.

http://api.jquery.com/jQuery.when/

Upvotes: 2

Andrew White
Andrew White

Reputation: 610

You can fix this by putting the "click" trigger in the complete function. I'm assuming from your syntax and tag you're using jQuery. Have a look at this link under "complete".

Upvotes: 0

Related Questions