Stop Watch II

[Total: 0    Average: 0/5]

This shows how to set up a stopwatch that has hours, minutes, seconds, and milliseconds.

Body Code:

<form name=exf1>
<input type=button value="Start" onclick="startIt()">
<input type=button value="Stop" onclick="stopTimers()">
<BR>
hour: <input type=text name=hour  value="<?>" onfocus=blur()>&nbsp;
min:  <input type=text name=tmin   value="<?>" onfocus=blur()>&nbsp;
sec:  <input type=text name=sec   value="<?>" onfocus=blur()>&nbsp;
msec: <input type=text name=mssec value="<?>" onfocus=blur()>
</form>
<script>
var _myTimer_ms = null;
var _myTimer_s  = null;
var _myTimer_m  = null;
var _myTimer_h  = null;
function updateMS() { document.exf1.mssec.value = (100+parseInt(document.exf1.mssec.value)) % 1000; }
function updateS()  { document.exf1.sec.value   = (1+parseInt(document.exf1.sec.value))    % 60;   }
function updateM()  { document.exf1.tmin.value  = (1+parseInt(document.exf1.tmin.value))   % 60;   }
function updateH()  { document.exf1.hour.value  = (1+parseInt(document.exf1.hour.value));          }
function startIt() {
  stopTimers();
  resetTime();
  _myTimer_ms = setInterval("updateMS()",100);
  _myTimer_s  = setInterval("updateS()",1000);
  _myTimer_m  = setInterval("updateM()",1000*60);
  _myTimer_h  = setInterval("updateH()",1000*60*60);
}
function stopTimers() {
  clearInterval(_myTimer_ms);
  clearInterval(_myTimer_s);
  clearInterval(_myTimer_m);
  clearInterval(_myTimer_h);
}
function resetTime() {
  document.exf1.mssec.value=0;
  document.exf1.sec.value=0;
  document.exf1.tmin.value=0;
  document.exf1.hour.value=0;
}

</script>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *