Creating a JavaScript Countdown

Do you know how many days you have before your taxes are due, how many more shopping days there are before Christmas, or the number of days before your company's trade show? With JavaScript, you can quickly create a countdown timer so that you can tell the viewer exactly how many days until an event. All you need is the following script:



The script uses the Date function in JavaScript to subtract the future date from the current date. It then takes that information (which is in the ever-so-useful milliseconds) and converts it to days. To use the script, you would simply call the function within the body of your document.

For instance, if you want to display the number of days until a certain copy editor's 40th birthday, you would insert the following code into the body section of your Web page:

Christine will make her way over the hill in
days.

Source: Ron Wilder
Viewed 4275 times