...

View Full Version : stopwatch



swordplay227
05-02-2006, 11:52 PM
if i try to make a stop watch with this simple code:


var seconds = 0
var minutes = 0
function custom(){
if (seconds<60){
minutes = minutes
seconds = parseFloat(seconds)+parseFloat(1)
}
else if (seconds==59){
minutes = parseFloat(minutes)+parseFloat(1)
seconds = 0
}
if (seconds<10){
seconds = "0"+seconds
}
document.byu.cougar.value = minutes+":"+seconds
setTimeout("custom()",1000)
}

then how can i make the STOPwatch STOP?!?

Philip M
05-03-2006, 08:36 AM
Presumably you need to stop, start and reset. This should do the trick.

http://javascript.internet.com/miscellaneous/stopwatch.html


If you want seconds rather than milliseconds change the three instances of
document.stpw.time.value = ms;
to
document.stpw.time.value = ms/1000;

or if you want to show whole seconds only
document.stpw.time.value = Math.round(ms/1000);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum