Dear friends, I need your help I need a script that starts the countdown on site load. For example, user loads the page and I need a countdown from 5 minutes to 0 minutes and 1 second, and I need it do be displayed on the site interactively. I hope you understood. Thanks for your help in advance. Regards, Radu
<div id="divTimer"></div> <script type="text/javascript"> var t = 20; var divT = document.getElementById("divTimer"); window.onload = countdown; function countdown() { if(t > 0) { divT.innerHTML = parseInt(t/60) + " minutes, " + (t % 60) + " seconds"; t = t - 1 setTimeout("countdown()", 1000); } } </script> Code (markup):
or to make it more 'clock-like': <div id="divTimer"></div> <script type="text/javascript"> var t = 300; var divT = document.getElementById("divTimer"); var d = new Date(); window.onload = countdown; function countdown() { if(t > 0) { d.setMinutes(parseInt(t/60)); d.setSeconds(t%60); divT.innerHTML = d.toTimeString().substr(3,5); t = t - 1 setTimeout("countdown()", 1000); } } </script> Code (markup):
yes, the timer will be displayed wherever the line: <div id="divTimer"></div> is placed... just make sure that the script is placed after the div.