I have a problem with settimeout.
When I call the initCountDown method on body's onLoad event. If I call the initCountDown on body's load, the button's code works fine afterwards.
However, if I do not place initcountDown in body's load, the button calls countDown method only once and settimeout does not function.
Any help or tips would be greatly appreciated.
Thanks
*********************************************
Expand|Select|Wrap|Line Numbers
- <SCRIPT language="JavaScript">
- var secs;
- var timeout;
- function initCountDown(init) {
- secs = init;
- countDown();
- }
- function countDown () {
- if (secs >= 0) {
- self.status = secs;
- secs = secs - 1 ;
- timeout = setTimeout(function(){countDown();}, 1000);
- } else {
- clearTimeout(timeout);
- }
- }
- </SCRIPT>
- <body onload="initCountDown(10)">
- <form>
- <INPUT type=submit id=btnCount value="Count Down" onClick = "initCountDown(10)">
- </form>
- </body>