/ Published in: JavaScript
Pure JavaScript countdown timer
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<html> <script language="JavaScript"> TargetDate = "12/31/2020 5:00 AM"; BackColor = "palegreen"; ForeColor = "navy"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; FinishMessage = "It is finally here!"; </script> <body> <form name="counter"><input type="text" size="8" style="border:none; cursor:default;" name="d2"> <input type="submit" name="Reset" value="Reset" onclick="reset();"> <input type="text" size="8" name="d3"> <input type="button" onClick="setVal();" value="Start" id="name" /> </form> <script> <!-- // var milisec=0 var seconds=30 document.counter.d2.value='30' function display(){ if (milisec<=0){ milisec=9 seconds-=1 } if (seconds<=-1){ milisec=0 seconds+=1 } else milisec-=1 document.counter.d2.value=seconds+"."+milisec setTimeout("display()",100) } display() function setVal() { var inputGet = document.counter.d3.value; document.counter.d2.value= inputGet; seconds = inputGet; milisec = 0; display(); } --> </script> </body> </html>