|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SetInterval behaving like setTimeout
This one's gotta be really obvious, but for the life of me, I just can't figure out what's wrong in the below code:
Code:
function test(){
alert('Hello world');
}
function startTetst(){
intervalReturnValue = window.setInterval(test(), 2000);
}
When I execute with an onclick, I'll get "Hello World" once, and once only. What have I screwed up? |
|
#2
|
||||
|
||||
|
You're passing the return value of test() to setInterval, which is undefined. You need to pass test itself.
Code:
function startTetst(){ // isn't there an extra "t" in there?
intervalReturnValue = setInterval(test, 2000);
}
__________________
Spreading knowledge, one newbie at a time. Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions IE7: the generation 7 browser new in a world of generation 8 browsers. Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around. |
|
#3
|
|||
|
|||
|
Ah, now I feel like a right ***. Thanks for that!
//No, I always write my tetst functions with an extra 't'. |
|
#4
|
||||
|
||||
|
You're welcome
![]() Actually calling a function instead of just referring to it is a common error. |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > SetInterval behaving like setTimeout |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|