...

View Full Version : Status Bar Countdown Script.



fredclown
04-15-2005, 12:01 AM
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>

fredclown
04-15-2005, 12:55 AM
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!!!!

fredclown
04-15-2005, 01:03 AM
Never mind. It didn't work ... just thought it did, cause if you hit the reload button the error dissapears ... <banging head against desk>.

glenngv
04-15-2005, 05:43 AM
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.

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 ()

fredclown
04-15-2005, 05:39 PM
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.


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)};



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum