SQL PHP HTML ASP JavaScript articles and free scripts to download
JavaScript Date

Resetting the timer funcitons in JavaScript

Here we will learn how to reset the timer function we have studied in part 1 of this tutorial. We can reset or clear the timer before the time out of the timer by using the function clearTimeout(). Here is the general syntax

clearTimeout(mytime)

mytime is the timer id we defined while activating the timer( please see the part 1 of this tutorial). It must be exactly same as one used in setTimeout function as it identify the timer with this.

setTimeout function sets the timer and executes it after the set time, before that if we want to cancel or reset the timer then we must use the clearTimeout function with timer id.

Now we will use the same domo ( in Timer Set of part 1 ) with the additional reset button for the timer. Here is the demo.

No reminder After 2 Secs After 5 Secs After 10 Secs

Now here is the code to be used inside your head tags

<script type="text/javascript">
function remind(msg1) {
var msg = "This is a reminder after " + msg1 +" Secs";
alert(msg);
}
</script>

This is the code we used for displaying the period buttons

<input type=radio name=rm value=no checked>No reminder
<input type=radio name=rm value=5000 OnClick="mytime=setTimeout('remind(2)',2000)">After 2 Secs
<input type=radio name=rm value=5000 OnClick="mytime=setTimeout('remind(5)',5000)">After 5 Secs
<input type=radio name=rm value=5000 OnClick="mytime=setTimeout('remind(10)',10000)">After 10 Secs
<input type=button value='Reset Timer' OnClick="clearTimeout(mytime)">

Timer set function Part I

Stopwatch script using setInterval()

Be the first to post comment on this article :


Google+

More on JavaScript Date & Time
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer