Thursday, October 5, 2023
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  6] [ 6]  / answers: 1 / hits: 26272  / 15 Years ago, wed, june 24, 2009, 12:00:00

Does anyone know how can I make a sleep in javascript before next line been read by the system?



example:



    1 var chkResult = Validation();
2 //sleep here for for 10 sec before the next line been read
3
4 document.getElementById('abc').innerHTML = chkResult;


For this example, how can I make the javascript sleep/wait in line 2 for 10 sec before it continues to read line 4? I had tried setTimeout('', 10000); but it's seems not working for me still...


More From » jquery

 Answers
19

I Have the Hat has given the right hint. Use the setTimeout method to execute your forth line code after 10 seconds:



var chkResult = Validation();
var timeout = window.setTimeout(function() {
document.getElementById('abc').innerHTML = chkResult;
}, 10000);


Storing the timeout ID in a variable can be handy if you want to clear a timeout.


[#99254] Friday, June 19, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mariselas

Total Points: 711
Total Questions: 117
Total Answers: 110

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
mariselas questions
Mon, Aug 30, 21, 00:00, 2 Years ago
Sat, Mar 20, 21, 00:00, 3 Years ago
Sat, May 16, 20, 00:00, 3 Years ago
Thu, Oct 10, 19, 00:00, 4 Years ago
;