PDA

View Full Version : setTimeout and passing variables


aenik
08-30-2002, 06:55 PM
Hello.
I am trying to set a timeout for a portion of my code that is inside of a for() loop, and the function receives a variable thats known to the function within which the for() loop takes place, a global (to that function) var array:
setTimeout("updateTag(getDirList(),'jpg',0,'../display/'+arr[cell]);",10000);
however i get an error, saying the array 'arr' is undefined. Not sure if setTimeout can receive variables.. if so, what am i doing wrong? if i bring the function call outside the setTimeout, it works, so my function call cant have a mistake. thanks.

boywonder
08-30-2002, 09:40 PM
try:
setTimeout("updateTag(getDirList(),'jpg',0,'../display/'"+arr[cell]+");",10000);

aenik
08-31-2002, 05:44 AM
i have tried that before, and it didnt help :|

joh6nn
08-31-2002, 07:01 AM
Originally posted by aenik
... a global (to that function) var array: ...

what do you mean by "to that function" ?

Ökii
08-31-2002, 10:49 AM
I assume 'cell' is being incremented in the for(loop)...

Perhaps subfunction the main function call...

function boing(data) {
updateTag(getDirList(),'jpg',0,'../display/'+arr[data]);
}

for(cell;;) {
setTimeout("boing(cell)",10000);
}