<html> <head> <title>Countdown clock</title> <script type = "text/javascript" > var running = false var endTime = null var timerID = null function startTimer() { running = true now = new Date() now = now.getTime() endTime = now + (1000 * 30 * 1) showCountDown() } function showCountDown() { var now = new Date() now = now.getTime() if (endTime - now <= 0) { stopTimer() alert("Time is up. Get back to work!.") } else { var delta = new Date(endTime - now) var theMin = delta.getMinutes() var theSec = delta.getSeconds() var theTime = theMin theTime += ((theSec < 10) ? ":0" : ":") + theSec document.forms[0].timerDisplay.value = theTime if (running) { timerID = setTimeout("showCountDown()",1000) } } } function stopTimer() { clearTimeout(timerID) running = false document.forms[0].timerDisplay.value = "0:00" } </script> </head> <body> <FORM> <INPUT TYPE="button" NAME="startTime" VALUE="Start 30 sec. Timer" > <INPUT TYPE="button" NAME="clearTime" VALUE="Clear Timer" ><p> <INPUT TYPE="text" NAME="timerDisplay" VALUE="0:30"> </FORM> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)