Creationguide.com

Adding a Countdown Element to a Web Page


You can add a couple lines of JavaScript code to your source code to create an automated countdown component on your Web site. The countdown component automatically counts down to the date of your choice.

Using the following code, you can customize the script by changing the January 1, 2008 date to any date, and you can customize the countdown message by modifying the Only --- days until January 1, 2008 text. The elements you can customize are displayed in red:

<script language="JavaScript">
var now = new Date();
var then = new Date("January 1, 2008");
var gap = then.getTime() - now.getTime();
gap = Math.floor(gap / (1000 * 60 * 60 * 24));
document.write("Only " + gap + " days until January 1, 2008");
</script>