Do you need to do live polling on events for your site on a time interval? For example, pull a new set of results from a twitter feed every 10 seconds. If the call/calculation takes awhile to complete, your user might be left with the feeling that the action they performed (clicking a button) didn’t do anything.
The crux of the problem is that the browser places all its “TODO” tasks resulting from events into a single queue. And unfortunately, re-drawing the “Status” DIV with the new “Calculating…” value is a separate TODO which goes to the end of the queue!
So, to fix your problem, you modify your onClick handler to be TWO statements (in a new function or just a block within onClick):
Populate the status “Calculating… may take ~3 minutes” into status DIV
Execute setTimeout with 0 timeout which calls “LongCalc” function. LongCalc function is almost the same as last time but obviously doesn’t have “Calculating…” Status DIV update as first step, and instead starts the calculation right away.
I stumbled onto this link on stackoverflow.com, it gives a full breakdown on the problem, the solution, and why you would want to do this. Read up, it’s a nugget of knowledge that can really save your bacon (and make you look like a much smarter developer than you really are)