I am relatively novice to javascript. I have written a simple counter program that starts count down from 10 till it reaches 1.
<script type="text/javascript">
function countDown(secs) {
var element = document.getElementById("status");
element.innerHTML = "Please wait for "+secs+" seconds";
if(secs < 1) {
clearTimeout(timer);
element.innerHTML = '<h2>Countdown Complete!</h2>';
element.innerHTML += '<a href="#">Click here now</a>';
}
secs--;
---> **var timer = setTimeout('countDown('secs')',1000);**
}
</script>
<div id="status"></div>
<script type="text/javascript">countDown(10);</script>
Then I tried passing parameter as '+secs+'
to the countDown function.
var timer = setTimeout('countDown('+secs+')',1000);
Above change works.
My question is why should I need to pass parameter as '+secs+' and NOT only 'secs' ? What difference does it make?