I am referring to this. Everything is still not clear.
fillTree()
which updates a tree, it has checkboxes.checkSelectedBoxes()
which is executed on window.onload
which checks for selected checkboxes.My question:
setTimeout()
will the other script function also stop and wait for my function to finish loading?What might be the case in this:
function fillTree(){...}
function checkSelectedBoxes(){...}
fillTree(); // This take time to get data. onLoad() doesnt work.
setTimeout(function(){ checkSelectedBoxes() },5000);
This returns me null values even after increasing the time interval. Does fillTree()
pause execution?
No, setTimeout
does not wait for you (hence, JS has no pause function). What setTimeout
does is set aside that task at a later time, and allow the next line to be executed. when that timeout is reached , it inserts that task into the execution line. and when no other code is running, it executes the function that was indicated.
what you want to do is give a callback to your fillTree()
and execute when it's done.
function fillTree(callback){
//do something very long
callback(); //execute passed function when it's done
}
fillTree(function(){
checkSelectedBoxes(); //executes only when fillTree finishes
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With