Home / code / javascript / scripts

Count down

Writer: Christophe Wolfs
Published: 27 March 2008

A simple script that counts down. For example seconds to newyear.

The actual code, put this in the HEAD section: 
<script language="JavaScript">
/*
Provided by http://www.webmaster2020.com
*/
  var timer = 25;
  function countdown()
  {
        if(timer >= 0)
        {
          document.all['swap'].innerHTML = timer; //swaps field in page
          timer -= 1;
          setTimeout("countdown()",1000);
        }
  }
</script>


Don't forget to load the script in the body-tag. 
<body onLoad="javascript:countdown()">


Place the following code where you want to number to appear 
<pre id='swap'>timer</pre>

 

TOP