pulpfiction Posted June 5, 2006 Share Posted June 5, 2006 HiThis is the code for the timer in mm:ss, but how to do it with milliseconds in it. mm:ss:milliseconds. var msec = 0var secs = 0var mins = 0var timerID = nullvar timerRunning = falsevar delay = 10function InitializeTimer(){ // Set the length of the timer, in seconds secs = 00 mins = 00 StopTheClock() StartTheTimer()}function StopTheClock(){ if(timerRunning) clearTimeout(timerID) timerRunning = false}function StartTheTimer(){ if (msec==990) { msec=0; secs=secs+1; } if (secs==60) { secs=0; mins=mins+1; } if (secs<10) secs="0"+secs; if (mins<10) mins="0"+mins; document.Form1.clockspot.value=mins+":"+secs+":"+msec secs = parseInt(secs,10) mins = parseInt(mins,10) self.status = secs msec = msec + 10; //secs = secs + 1 timerRunning = true timerID = self.setTimeout("StartTheTimer()", delay)} Link to comment Share on other sites More sharing options...
scott100 Posted June 5, 2006 Share Posted June 5, 2006 It already uses milliseconds Or do you mean in the status bar? <html><head><script>var msec = 0var secs = 0var mins = 0var timerID = nullvar timerRunning = falsevar delay = 10function InitializeTimer(){ // Set the length of the timer, in seconds secs = 00 mins = 00 StopTheClock() StartTheTimer()}function StopTheClock(){ if(timerRunning) clearTimeout(timerID) timerRunning = false}function StartTheTimer(){ if (msec==990) { msec=0; secs=secs+1; } if (secs==60) { secs=0; mins=mins+1; } if (secs<10) secs="0"+secs; if (mins<10) mins="0"+mins; document.Form1.clockspot.value=mins+":"+secs+":"+msec secs = parseInt(secs,10) mins = parseInt(mins,10) self.status = mins+":"+secs+":"+msec msec = msec + 10; //secs = secs + 1 timerRunning = true timerID = self.setTimeout("StartTheTimer()", delay)}</script></head><body onload="StartTheTimer()"><form name="Form1"><input type="text" name="clockspot" /><form></body></html> Link to comment Share on other sites More sharing options...
pulpfiction Posted June 5, 2006 Author Share Posted June 5, 2006 My bad, i posted the modified code, anyways i think this timer runs slower compared to the normal clock.... Link to comment Share on other sites More sharing options...
scott100 Posted June 5, 2006 Share Posted June 5, 2006 My bad, i posted the modified code, anyways i think this timer runs slower compared to the normal clock....<{POST_SNAPBACK}> It looked ok to me...What about this one, it's quite neat: http://proft.50megs.com/stopwatch.htmlEDIT Your right it does run slower, when compaired to the link above it's out. Link to comment Share on other sites More sharing options...
pulpfiction Posted June 5, 2006 Author Share Posted June 5, 2006 yeah this should work for me, thanks... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now