Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

setTimeout and setInterval ?

Posted on 2001-08-13
5
Medium Priority
?
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

688 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