I would like to put a countdown timer on my webpage which starts from 60 to 0 seconds. What is the code to implement that? It is a html webpage btw. Most of the codes I find have a target date. I do not wish to use a target date. I just wish to have the timer start counting down from 60 to 0 seconds once the page is loaded, and have that decreasing number displayed real time.
"once the page is loaded" says Javascript. var timer = 60; function countDown() { document.getElementById('t').innerHTML = timer-- + ' seconds left'; if(timer == 0) { //return or do whatever you want once the time has run down to 0 } setTimeout("[I]countDown()[/I]",[I]1000[/I]); } <body onload="countDown();> ... <div id="t"></div> Code (markup):
Where do I post the top part of the code? Before or after the head tag? Does the code display the number 60 and start decreasing it to 0 on the webpage?
1) The Javascript goes wherever you have <script></script> tags. The body tag Javascript goes in your existing body tag. 2) Yes - in the div with the id of "t". Put that wherever you want the "x seconds left" (or whatever text you want to use) to appear.
I tried using the code but the number didn't change. It remained at 60. This is my webpage: http://www.mindreality.com/secrets2.html I have attachd the html file.
I managed to make it work. But how do I make it the same font as my words? And how do I make it fit in the middle of a sentence instead of in a new paragraph?