0

I need to use a timer on my page. I wrote in document.ready function the code below:

var timerForLoadingResult=  window.setInterval('checkSearchIsCompleted()',4000)
function checkSearchIsCompleted() {      
    alert('test');        
}

But it's not calling the function every 4 seconds. It's showing an error which says that the object is not found... What's the problem?

1 Answer 1

4

Proper syntax is to pass the function name alone:

var timerForLoadingResult = window.setInterval(checkSearchIsCompleted,4000);
Sign up to request clarification or add additional context in comments.

1 Comment

Though the reason it's not working is because a string can only be evaluated in global scope, while the OP mentioned that the above code is inside document.ready.

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.