Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery to detect select finished loading
    primarykey
    data
    text
    <p>How would you approach this question: I have 3 select (dropdown), one is person, one is State, one is city list.</p> <p>When a state is selected, all city within that state will be loaded to city list</p> <p>My problem when the person is changed, I can change the select (dropdown) with</p> <pre><code>$('#State').find('[value="' + user.State + '"]').prop('selected', true); </code></pre> <p>since state is pre-loaded. after that I had</p> <pre><code>$('#State').trigger('change'); </code></pre> <p>to load the city list</p> <p>My question is how do I detect $('#City') finished loading from ajax? Maybe something like this:</p> <pre><code>$('#City').on('load', function(){ $('#City').find('[value="' + user.City+ '"]').prop('selected', true); }); </code></pre> <p>but I think I'm doing something wrong...</p> <p>Any advise? thanks!</p> <p>Here's the complete code:</p> <pre><code>$('document').ready(function () { $('#State').live('change', function () { GetCityList($(this).val()); }); // when loading, detect query string for user's name var user = GetUserInfo(); if (user.Name != '') { $('#State').find('[value="' + user.State + '"]').prop('selected', true); } $('#State').trigger('change'); // this line will not work because City has not finished loading $('#City').find('[value="' + user.City + '"]').prop('selected', true); }); function GetCityList(State) { $.getJSON('/Handler.ashx?State=' + State, function (data) { var html = ''; // process data to produce html $('#CityList').html(html); }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload