You are here:About>Computing & Technology>JavaScript
About.comJavaScript

Countdown Timer

2. The Timer Script

clr gif
Join the Discussion

Questions? Comments?

More of this Feature

Introduction

To add the countdown script to your web page you first need to select the code from the text box below (there is a highlight all button beneath it to make this easier) and copy it into a file called count.js.

Amend the values for month, day, hour, and tz to reflect the date/time at your location to which you want the countdown timer to count down. You can also amend the start function if required to handle other onload functioning for your page.

You next link it into the head of your page using the following code:

<script type="text/javascript" src="count.js">
</script>

The final step is to add the following code into the body of your web page where you want the countdown to be displayed:

<span id="cd"></span>

If you need to change the id associated with the countdown timer simply change the value from cd to your required value in both the span tag and the lab variable at the top of the script.

From Stephen Chapman,
Your Guide to JavaScript.
FREE Newsletter. Sign Up Now!
Newsletters & RSSEmail to a friendSubmit to Digg
 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.