0
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 function.

I have tried this:

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

But it's not working.

What is the exact way to do this?

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

1 Comment

I'd recommend reading an article regarding javascript timers and scope. Here's a tutorial I found with a quick Google search - switchonthecode.com/tutorials/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.