INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Helpful Links

How to use timers in HTML by Targol
Posted: 30 Oct 02 (Edited 30 Oct 02)

To add timers capabilyties to an html page, you'v got to use the window.setInterval method. It's interface is this one :

oInterval=window.setInterval(FctToCall, TimeWait)
with
  FctToCall :
string containing the name of the function to call
  TimeWait :
Time to wait (in milliseconds) before calling FctToCall
  
Here is an exemple :

<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>

Back to HTML, XHTML & CSS FAQ Index
Back to HTML, XHTML & CSS Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close