views:

136

answers:

1

hello,

setTimeout("refresh()", 2*15000 );

This is a code from my javascript

here setTimeout is a built in function and refresh is a function which i have declared.

i want to pass a variable (cval1) to this refresh fuction

i have tried this

setTimeout("refresh(cval1)", 2*15000 );

bit its not working

What is the exact way to do this??

Please help me ...

Thanks

+2  A: 

As first parameter of setTimeout pass a function instead of a string, so you have access to all variables in current scope.

setTimeout(function(){refresh(cval1)}, 2*15000);
Rafael
I'd recommend reading an article regarding javascript timers and scope. Here's a tutorial I found with a quick Google search - http://www.switchonthecode.com/tutorials/javascript-tutorial-using-setinterval-and-settimeout
Andy E