Creating a Countdown

Sooner or later, you’ll want to put a countdown on your pages that tells the user how many days or hours until a particular event. Script 12.8 (HTML) and Script 12.9 (JavaScript) lets one of the authors know his responsibilities, in no uncertain terms, as you can see in Figure 12.6.

Figure 12.6. Loading this page gives one of the authors his marching orders.

To create a countdown:

1.
var allTags = document.getElementsByTagName("*");
Create a new allTags array, and fill it with every tag on the page.
2.
for (var i=0;i<allTags.length; i++) { if (allTags[i].className.indexOf("daysTill") > -1) { allTags[i].innerHTML = showTheDaysTill(allTags[i].id); ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.