32
rated 0 times
[
35]
[
3]
/ answers: 1 / hits: 41821
/ 11 Years ago, thu, june 13, 2013, 12:00:00
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?
More From » settimeout