Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use timers in HTML

Helpful Links

How to use timers in HTML

by  Targol  Posted    (Edited  )
To add timers capabilyties to an html page, you'v got to use the window.setInterval method. It's interface is this one :
Code:
oInterval=window.setInterval(FctToCall, TimeWait)
with
Code:
  FctToCall :
string containing the name of the function to call
Code:
  TimeWait :
Time to wait (in milliseconds) before calling
Code:
FctToCall

Here is an exemple :
Code:
<Html>
<head>
<Script language="Jscript">
var oInterval;

function RemindMsg(msg) {
  oInterval=window.setInterval("ShowDelayedMsg('" + msg + "')", 2000);
  // function stopTimer() will be called every 2 seconds
  // Note that you can add any parameters to the function call.
}

function ShowDelayedMsg(msg) {
  var oDiv=document.getElementById("container");
  var oldContent = oDiv.innerHTML;
  var curDate=new Date();
  oDiv.innerHTML = oldContent + curDate + " : " + msg + "<BR>";
}

function stopTimer() {
  window.clearInterval(oInterval);
  // the timer is now stopped
}
</script>
</head>
<body>
  <input type="button" value="start timer" onclick="RemindMsg('another message');"/>
  <input type="button" value="stop timer" onclick="stopTimer();"/>
  <div id="container"></div>
</body>
</html>
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top