I’m using javascript to create timers that will start a count down after the page is loaded. I need to do the calculation of seconds for the timers in php on the page that calls this page with the javascript. I then pass the seconds when I write the javascript using php. Here I’m just showing the javascript with the seconds hard-coded for each timer. I’ve tried testing this as is (with the javascript hard-coded just as shown here), but all it will do is display the starting point for each timer but won’t advance beyond that. It is supposed to show the timers counting down each second.
Thanks for any suggestions.
[code]
<script type=’text/javascript’>
function GetCount(secondsPassed, iid){
amount = secondsPassed;
if(amount < 0){
document.getElementById(iid).innerHTML=’Now!’;
}
else{
days=0;hours=0;mins=0;secs=0;out=”;
days=Math.floor(amount/86400);
amount=amount%86400;
hours=Math.floor(amount/3600);
amount=amount%3600;
mins=Math.floor(amount/60);
amount=amount%60;
secs=Math.floor(amount);
if(days != 0){out += days +’ d ‘;}
if(days != 0 || hours != 0){out += hours +’ h ‘;}
if(days != 0 || hours != 0 || mins != 0){out += mins +’ m ‘;}
out += secs +’ s’;
document.getElementById(iid).innerHTML=out;
setTimeout(function(){GetCount(secondsPassed,iid)}, 1000);
}
}
window.onload=function(){
GetCount(‘120’, ‘countbox1′);
GetCount(’60’, ‘countbox2′);
GetCount(’30’, ‘countbox3’);
};
</script>
<div id=”countbox1″></div>
<div id=”countbox2″></div>
<div id=”countbox3″></div>