Posted By


Sullan on 08/17/10

Tagged


Statistics


Viewed 651 times
Favorited by 0 user(s)

Countdown timer


/ Published in: JavaScript
Save to your folder(s)

Pure JavaScript countdown timer


Copy this code and paste it in your HTML
  1. <html>
  2. <script language="JavaScript">
  3. TargetDate = "12/31/2020 5:00 AM";
  4. BackColor = "palegreen";
  5. ForeColor = "navy";
  6. CountActive = true;
  7. CountStepper = -1;
  8. LeadingZero = true;
  9. DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
  10. FinishMessage = "It is finally here!";
  11. </script>
  12. <body>
  13. <form name="counter"><input type="text" size="8" style="border:none; cursor:default;" name="d2">
  14. <input type="submit" name="Reset" value="Reset" onclick="reset();">
  15. <input type="text" size="8" name="d3">
  16. <input type="button" onClick="setVal();" value="Start" id="name" />
  17. </form>
  18. <script>
  19. <!--
  20. //
  21. var milisec=0
  22. var seconds=30
  23. document.counter.d2.value='30'
  24.  
  25. function display(){
  26.  
  27.  
  28.  
  29. if (milisec<=0){
  30. milisec=9
  31. seconds-=1
  32. }
  33. if (seconds<=-1){
  34. milisec=0
  35. seconds+=1
  36. }
  37. else
  38. milisec-=1
  39. document.counter.d2.value=seconds+"."+milisec
  40. setTimeout("display()",100)
  41. }
  42. display()
  43.  
  44. function setVal() {
  45.  
  46. var inputGet = document.counter.d3.value;
  47. document.counter.d2.value= inputGet;
  48. seconds = inputGet;
  49. milisec = 0;
  50. display();
  51. }
  52.  
  53. -->
  54. </script>
  55.  
  56. </body>
  57. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.