Example 3—Simple Countdown Counter

This is a really handy script if you want to have a counter on the page. A counter can be handy for things such as showing when a page or image might refresh if you have, say, a Web cam that updates an image on a regular basis. The actual page change can be done by a meta tag refresher (which appears following the title tag).

Here is a simple example, the results of which are shown in Figure 15.4:

 <html> <head> <title>A Simple Page</title> <meta http-equiv="refresh" content="30"> <script language="JavaScript"> <!-- Cloaking device on! var x=30; var y=1; function startClock(){ x=x-y; document.form1.clock.value = x; timerID=setTimeout("startClock()", 1000); } // Cloaking device off --> </script> </head> <body ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.