By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,567 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

Javascript alert/delay confusion

P: 1
This problem is very similar to that experienced in, but the solution there doesn't seem to apply here.

I have a function which works fine with the alert call in place below, but a delay (using another function defined elsewhere, which does work by the way) doesn't. Similarly if no delay is put in place it fails to complete the next line. It certainly appears that a value hasn't been finalised at that point, but I'm confused why a delay won't work. If I click the alert box immediately (i.e. a delay of 1-2 seconds) it works.

Expand|Select|Wrap|Line Numbers
  1. function loadProperties() {
  2.     new Ajax.Updater('property_div', baseUrl+'/property/ajaxCorrespondenceProperties', {
  3.         method:'post', postBody:'town_id='+$F('town_id')
  4.     });
  6.     //alert("setting property selection");
  7.     //pause(5000);
  9.     townId = document.getElementById('town_id').value;
  10.     propertyId = document.getElementById('property_id').value;
  11. }
Any ideas?
Nov 22 '06 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
The most likely cause is that the response is not yet ready because the Ajax call is asynchronous. Move the statements to an onComplete event handler or when the readyState is 4 and the status is 200.
May 29 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.