Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    dep
    dep is offline
    Regular Coder
    Join Date
    Nov 2005
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Displaying a "please wait" for long computations.

    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:

    Code:
    <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

  • #2
    dep
    dep is offline
    Regular Coder
    Join Date
    Nov 2005
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    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?

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    A simple change:
    Code:
    function initLoad(window, element){
        document.getElementById('loading').style.display='block';
        setTimeout(function(){thefunction(window,element);}, 1);
        document.getElementById('loading').style.display='none';
    }
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    dep
    dep is offline
    Regular Coder
    Join Date
    Nov 2005
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks! I will try it out.

  • #5
    dep
    dep is offline
    Regular Coder
    Join Date
    Nov 2005
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That worked! awesome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •