Here is my code. I am simply trying to count down from a specified number of seconds, which is loaded from a db using php. The problem is that it shows the amount of time, but doesn’t count down. I have looked over at least two dozen scripts, and the only difference is that I am passing a variable to it in seconds, not a timestamp or something that uses the date() function. Anyway, please have a quick look, and help a fellow out… Thanks, so very much…
This is in my head section…
[CODE]var secondstoadd = 0;
var secondsremaining = 0;
function timer(secondstoadd)
{
secondsremaining = secondstoadd;
if (secondsremaining < 0)
{
return;
}
var seconds = Math.floor(secondsremaining % 60);
secondsremaining = secondsremaining/60;
var minutes = Math.floor(secondsremaining % 60);
secondsremaining = secondsremaining/60;
var hours = Math.floor(secondsremaining % 24);
secondsremaining = secondsremaining/24;
var days = Math.floor(secondsremaining);
var outStr = “”;
if (seconds<=9) { seconds = “0” + seconds; }
if (minutes<=9) { minutes = “0” + minutes; }
if (hours<=9) { hours = “0” + hours; }
var outStr = days + ‘:’ + hours + ‘:’ + minutes + ‘:’ + seconds;
document.getElementById(‘countdown’).innerHTML=outStr;
secondsremaining = (secondsremaining – 1);
window.setTimeout(‘timer(‘+ secondsremaining + ‘)’);
}
And This is my call to the function…
[CODE]<td><div id=’countdown’><script type=”text/javascript”>new timer(” . $row[‘arrivaltime’]. “);</script></div></td>
Where $row[‘arrivaltime’] is a php var that populates the html with the number of seconds until you would arrive at your destination…
Thanks again.
Savaal