开发者

Jquery delay to stop code like an alert box does

开发者 https://www.devze.com 2023-04-11 16:22 出处:网络
开发者_StackOverflow社区If I use an alert to stop the code running the ddl ‘Suburb1\' is populated with the correct value if I use ‘delay’ the value is not set. I need some way of stopping the code

开发者_StackOverflow社区If I use an alert to stop the code running the ddl ‘Suburb1' is populated with the correct value if I use ‘delay’ the value is not set. I need some way of stopping the code running after ‘change’ so that $('#Suburb1').val(SuburbVC); is not fired straight away when the ddl Suburb1 is getting populated from the DB.

if ($(this).attr("checked") == true) {
var PostCode = $('#PostCode').val();
var SuburbVC = $('#SuburbVC').val();

    $('#PostCode1').val(PostCode);  

    // Another function is called which populates Dropdown list from DB
    // If I use delay Suburb1 is not populated
    $('#PostCode1').change().delay(5000);  

    //If I use an alert Suburb1 is populated 
    // alert('delay');
    $('#Suburb1').val(SuburbVC);
  } else {
    $('#PostCode1').val("");
}

Thanks


You are tackling this problem the wrong way; You should add a callback function to execute the rest of the code, after you populate the values from the DB.

How do you populate the values from the DB? AJAX? If so, add a function call with the code you want to execute after the data is ready, to the success handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消