Goose87 Posted July 10, 2009 Share Posted July 10, 2009 Dear all, I have the following script, but there is a problem that I am not sure how to resolve. Someone looked at this before and mentioned that the reason it didn't display straight away was because the timer minuses one second, and then displays. This looks very unprofessional. If someone could help me out and adjust the script to show the timer instantly as the page loads, I would be extremely grateful. If you could mention which bit you adjusted too, I would appreciate it as I want to learn. Thank you to all in advance, James <script type = "text/javascript"> var timeInSecs = null; var ticker = null; function startTimer(secs){ timeInSecs = parseInt(secs); ticker = setInterval( "tick( )", 1000 ); } function tick() { var secs = timeInSecs; if (secs > 0) { --timeInSecs; } else { clearInterval( ticker ); } var hours = Math.floor( secs / 3600); secs %= 3600; var mins = Math.floor( secs / 60 ); secs %= 60; var pretty = ( (hours < 10 ) ? "0" : "" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0" : "" ) + secs; document.getElementById("countdown").innerHTML = pretty; } startTimer(<?php echo "$timer"; ?>); </script> Link to comment https://forums.phpfreaks.com/topic/165489-countdown-timer-script-improvement/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.