Solved

setTimeout and setInterval ?

Posted on 2001-08-13
5
416 Views
Last Modified: 2008-02-01
What is the different between setTimeout and setInterval ?
And how do I stop them ?
0
Comment
Question by:superCombo2001
  • 3
5 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6380088
setTimeout will act like a timer, and execute the statement after the specified interval. That will happen only once!
setInterval however will act as a true timer and execute the statement more than one time. After the specified interval the timer will be set back to 0 and count again. This will continue until you use the clearInterval method.

regards,
CJ
0
 

Author Comment

by:superCombo2001
ID: 6380110
how do I use clearInterval and setInterval ?
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 30 total points
ID: 6380141
Put this in between script tags:

var myInterval = null;
myInterval = setInterval("alert('hi')",1000);

and whenever you need to stop it you call:
clearInterval(myInterval);

instead of the alert('hi') you can use ANY javascript statement to be called.

regards,
CJ

0
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6381507
Or if you want a number of statements to be run you can call a function :)

myInterval = setInteral("myfunction(), 1000)

Regards,
CyberSoft
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6383890
>> ANY javascript statement
>> if you want a number of statements to be run you can call a function

---

the same
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question