Stop Watch:
Seconds:
Minutes:
Hours:
Code:
stopwatch.js
Highlight
var seconds = 0 var minutes = 0 var hours = 0 var timerID = null var timerRunning = false var startClicked = false function resetclock(){ seconds = 0 minutes = 0 hours = 0 timerID = null timerRunning = false startClicked = false document.clock.Hours.value = "" document.clock.Minutes.value = "" document.clock.Seconds.value = "" } function stopclock(){ if(timerRunning) clearTimeout(timerID) timerRunning = false startClicked = false } function startclock(){ if (startClicked != true){ showtime() startClicked = true } } function showtime(){ seconds = seconds + 1 if (seconds == 60) { seconds = 0 minutes = minutes+1 } if (minutes == 60) { minutes = 0 hours = hours+1 } var timeValuehr = "" + ((hours <10) ? "" : "") + hours var timeValuemin + ((minutes < 10) ? "" : "") + minutes var timeValuesec + ((seconds < 10) ? "" : "") + seconds document.clock.Hours.value="timeValuehr" document.clock.Minutes.value="timeValuemin" document.clock.Seconds.value="timeValuesec" timerID="setTimeout("showtime()",1000)" timerRunning="true" }
Place in the <HEAD>:
Highlight
Place in the <BODY>:
Highlight
Seconds:
Minutes:
Hours: