[thelist] Javascript - order of code execution

Alex thelist at rabarts.co.uk
Wed May 11 06:29:45 CDT 2005


I am hoping there are some Javascript gurus out there that are able to 
answer my seemingly simple, yet frustrating, problem.

I have a Javascript function that takes several seconds to run and I am 
attempting to display a 'Calculating...' message during that time.  The 
order of the code goes:

1. Display 'Calculating...' message
2. Perform lengthy operation

Yet when the script is executed, it *appears* to run in the opposite order:

1. Perform lengthy operation
2. Display 'Calculating...' message

Now, where this gets a little strange is when an alert() is introduced 
after step 1:

1. Display 'Calculating' message
2. alert()
3. Perform lengthy calculation

In this case, the code *does* execute in the correct order(!).  Clearly 
I don't want the superferlous alert(), though.

Here is a stripped-down script to demonstrate the problem:

http://tinyurl.com/9l67t

Does anyone have an idea of what is causing this problem or how I might 
work around it?  Ideas greatly appreciated.

Alex


More information about the thelist mailing list