/    Sign up×
Community /Pin to ProfileBookmark

Can’t Solve setTimeout issue….

So I am using the below code on my site, which should hopefully endlessly call a function while looping. The only problem is that is calls the click_sidebar(0), and then never calls it again, even though I know the loop is running….. I think I’m doing something wrong, but I can’t for the life of me figure out what.

Any help is greatly appreciated.

function raiseAlerts(nosofitems)
{
var i=0;
while (i<=nosofitems)
{
t=setTimeout(“click_sidebar(” + i + “)”,1000);
i=i+1;
}
//Add Code to Then Repeat Function All Over Again from 0 on Endless Loop
}

raiseAlerts(50);

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayJan 04.2008 — Try changing it to:

var i=0;
function raiseAlerts(nosofitems)
{

if (i&lt;=nosofitems)
{
i++;
click_sidebar( i );
t=setTimeout("raiseAlerts("+nosofitems+")",1000);
}
//Add Code to Then Repeat Function All Over Again from 0 on Endless Loop
}

raiseAlerts(50);
Copy linkTweet thisAlerts:
@drbigfreshauthorJan 04.2008 — But now I cna't figure out how to make it loop endlessly... Once it runs I want to set i back to 0 and run all over again....

This is the code I used to get it working....

<!--

var i = 0;

function showNext() {

click_sidebar(i);

if (++i <= <?php echo count($PeopleToMap)?>) setTimeout("showNext()", 5000);

}

setTimeout("showNext()", 5000);

//-->
Copy linkTweet thisAlerts:
@TheBearMayJan 04.2008 — How's this:

var i=0;
function raiseAlerts(nosofitems)
{

if (i&lt;=nosofitems) {
i++;
click_sidebar( i );
} else i=0;
t=setTimeout("raiseAlerts("+nosofitems+")",1000);
}

raiseAlerts(50);
×

Success!

Help @drbigfresh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...