Ryflex Posted October 8, 2010 Share Posted October 8, 2010 Hi all, I'm looking for a countdown clock where the input is an amount of seconds, instead of going towards a targetdate. Is anyone able to help me out here??? Ryflex Link to comment https://forums.phpfreaks.com/topic/215431-countdown-clock-with-seconds-input/ Share on other sites More sharing options...
.josh Posted October 8, 2010 Share Posted October 8, 2010 <!-- div that displays the number of seconds left --> <div id='cd'>X</div> <script type='text/javascript'> // enter in starting number (in seconds) here. countdown(15); // example: 15 seconds // function to count down from start seconds function countdown(start) { countdown.secondsLeft = (typeof(start) != 'undefined')? start : countdown.secondsLeft; document.getElementById('cd').innerHTML = countdown.secondsLeft; if (countdown.secondsLeft > 0) window.setTimeout("countdown();",1000); countdown.secondsLeft--; } </script> Link to comment https://forums.phpfreaks.com/topic/215431-countdown-clock-with-seconds-input/#findComment-1120358 Share on other sites More sharing options...
Ryflex Posted October 9, 2010 Author Share Posted October 9, 2010 Thanks for the reply, I tested the code but all I get as output is "X" Ryflex Link to comment https://forums.phpfreaks.com/topic/215431-countdown-clock-with-seconds-input/#findComment-1120487 Share on other sites More sharing options...
Ryflex Posted October 9, 2010 Author Share Posted October 9, 2010 Hi all, Found a great script: <script language="JavaScript"> var tijd= <?php echo "$time"; ?> function countdown(){ if(tijd>0){ if(tijd>86399){ dagen=Math.floor(tijd/3600/24) uren=Math.floor((tijd-dagen*3600*24)/3600) minuten=Math.floor((tijd-dagen*3600*24-uren*3600)/60) seconden=Math.floor(tijd-dagen*3600*24-uren*3600-minuten*60) if( uren < 10 ) { uren = '0'+uren ;} if( minuten < 10 ) { minuten = '0'+minuten ;} if( seconden < 10 ) { seconden = '0'+seconden ;} var zichttijd=dagen+":"+uren+":"+minuten+":"+seconden } else{ uren=Math.floor(tijd/3600) minuten=Math.floor((tijd-uren*3600)/60) seconden=Math.floor(tijd-uren*3600-minuten*60) if( uren < 10 ) { uren = '0'+uren ;} if( minuten < 10 ) { minuten = '0'+minuten ;} if( seconden < 10 ) { seconden = '0'+seconden ;} var zichttijd=uren+":"+minuten+":"+seconden } document.getElementById("countdown").innerHTML=zichttijd; countdownTimer=setTimeout("countdown()",1000); tijd=tijd-1 } else{ document.write("Ready for Upgrade") } } </script> <SPAN id="countdown"></SPAN> <SCRIPT language="JavaScript">countdown();</SCRIPT> Thanx for the replies. Ryflex Link to comment https://forums.phpfreaks.com/topic/215431-countdown-clock-with-seconds-input/#findComment-1120501 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.