Solved

setTimeout and setInterval ?

Posted on 2001-08-13
5
413 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
Comment Utility
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
Comment Utility
how do I use clearInterval and setInterval ?
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 30 total points
Comment Utility
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
Comment Utility
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
Comment Utility
>> ANY javascript statement
>> if you want a number of statements to be run you can call a function

---

the same
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now