...

View Full Version : Displaying a "please wait" for long computations.



dep
01-26-2006, 05:54 PM
Hello. I have created a DIV that is invisible by default. I want it to be visible at the beginning of the script and then hide at the end... This, however does not work:



<script>
document.getElementById('loading').style.display='block';
...lots of javascript
document.getElementById('loading').style.display='none';
</script>


Because it seems like it starts trying to render the HTML before it shows the popup window.. So really, what happens is, it does what is between the block/none tags, and THEN renders the block/none afterwards.. Really fast-like. So you never see it...

So, instead, you get..

looooong paaaaaaause.. really fast: SHOW--HIDE.

Any way to work around that?

Any help is greatly appreciated.

dep

dep
01-26-2006, 09:11 PM
the way to fix it is to:
document.getElementById('loading').style.display='block';
setTimeout("thefunction()", 1);
document.getElementById('loading').style.display='none';

however, if this is already IN a function like this:



function initLoad(window, element){
document.getElementById('loading').style.display='block';
setTimeout("thefunction()", 1);
document.getElementById('loading').style.display='none';
}

function thefunction(window, element){
alert(window + ' ' + element);
///Window and element are now lost.
}



How can I gracefully pass the window/element?

liorean
01-26-2006, 09:16 PM
A simple change:
function initLoad(window, element){
document.getElementById('loading').style.display='block';
setTimeout(function(){thefunction(window,element);}, 1);
document.getElementById('loading').style.display='none';
}

dep
01-26-2006, 09:24 PM
Thanks! I will try it out.

dep
01-26-2006, 09:53 PM
That worked! awesome.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum