Stopwatch Made Simple

[Total: 0    Average: 0/5]

This shows how to set up a simple stopwatch.

Body Code:

<form name=exf1>
<input type=button value="Start" onclick="startIt()">
<input type=button value="Stop" onclick="stopIt()">
<BR>
<input type=text name=delta value="<?>" onfocus=blur()>
</form>
<script>
var _startTime = 0;
var _myTimer = null;
var _myDelta = 50; // 50 milliseconds
function updateIt() {
  document.exf1.delta.value = theDelta();
}
function startIt() {
  clearInterval(_myTimer);
  _startTime = new Date();
  _myTimer = setInterval("updateIt()",_myDelta);
}
function stopIt() {
  clearInterval(_myTimer);
  document.exf1.delta.value = theDelta();
}
function theDelta() {
  var _tempTime = new Date();
  return (_tempTime.getTime() - _startTime.getTime());
}
</script>

Times Viewed: 1

Leave a Reply

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