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
    New Coder
    Join Date
    Feb 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Status Bar Countdown Script.

    Any ideas why this works fine is all the borwsers except IE. IE gives an error on the window.onload? However if I put the onload in the body tag ... no error. Confused about this. Any help would be appreciated.

    I might add that it actually does work in IE, it just shows that annoying litle yellow eclamation point saying that there is a JS error.

    <html>
    <head>
    <title>Count Down</title>
    <script>
    function countDown(tick) {
    if (tick == 0)
    {window.status = "Your session has expired and you have been logged off.";
    return;}
    var time = "Time remaining till you are automatically logged out. ";
    var minute = Math.floor(tick / 60);
    if (minute < 10)
    {time += "0";}
    time += minute + ":";
    var second = tick % 60;
    if (second < 10)
    {time += "0";}
    time += second;
    window.status = time;
    --tick;
    var command = "countDown(" + tick + ")";
    window.setTimeout(command,1000);
    }
    window.onload = countDown(1200);
    </script>
    </head>
    <body>
    </body>
    </html>
    Last edited by fredclown; 04-14-2005 at 11:07 PM.

  • #2
    New Coder
    Join Date
    Feb 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Solution?

    Well, I found something that worked ... not sure why. I took the same code and moved it into a .js file and then included the script and it worked. Go fig. SAME CODE!!!! URG!!!! WHY MUST MICROSOFT DO THIS TO ME!!!!

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Hmm

    Never mind. It didn't work ... just thought it did, cause if you hit the reload button the error dissapears ... <banging head against desk>.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Quote Originally Posted by fredclown
    I might add that it actually does work in IE, it just shows that annoying litle yellow eclamation point saying that there is a JS error.
    You need to double-click that icon to see the details of the error.
    But as I see your code, the error is you missed the closing brace for the function. If you indent your codes, it is easier to debug those kinds of errors.
    Code:
    function countDown(tick) {
      if (tick == 0)
      {
        window.status = "Your session has expired and you have been logged off.";
        return;
      }
      var time = "Time remaining till you are automatically logged out. ";
      var minute = Math.floor(tick / 60);
      if (minute < 10)
      {
        time += "0";
      }
      time += minute + ":";
      var second = tick % 60;
      if (second < 10)
      {
        time += "0";}
        time += second;
        window.status = time;
        --tick;
        var command = "countDown(" + tick + ")";
        window.setTimeout(command,1000);
      }
    <--- you need the } here
    window.onload = function(){countDown(1200)};
    You also need to change the window.onload part. You are not actually assigning countDown() function on window.onload but directly calling it. The code I set above is the proper way of assigning event handlers. If the function has no parameter, the code would be:

    window.onload = countdown; //no ()

  • #5
    New Coder
    Join Date
    Feb 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool Thanks

    Normally I do indent, it just messed up when I cut and pasted into the box. Actually I did close all of the braces. You missed the one that I colored blue. The problem wasn't missed braces, but the way I called the function. Thanks for the info on how to properly call the function.

    Code:
    function countDown(tick) {
      if (tick == 0)
      {
        window.status = "Your session has expired and you have been logged off.";
        return;
      }
      var time = "Time remaining till you are automatically logged out. ";
      var minute = Math.floor(tick / 60);
      if (minute < 10)
      {
        time += "0";
      }
      time += minute + ":";
      var second = tick % 60;
      if (second < 10)
      {
        time += "0";} <--
        time += second;
        window.status = time;
        --tick;
        var command = "countDown(" + tick + ")";
        window.setTimeout(command,1000);
    }
    window.onload = function(){countDown(1200)};


  •  

    Posting Permissions

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