I have two javascript codes .
Two codes working for the same work , but there is one code work and the other code does not work .
Work
var i = 0;
function slideShow(){
i++;
document.getElementsByName('SearchBox')[0].value = i
setTimeout(slideShow, 1000);
}
Not work
var i = 0;
function slideShow(){
setTimeout(function(){
i++;
document.getElementsByName('SearchBox')[0].value = i
}, 1000);
}
Why one works and the other does not work
The first version, when called, does something, then sets a timeout to call itself again.
The second version, when called, sets a timeout to execute some code. It does not call itself again.