I'm attempting to build a second timer using JavaScript. The following code works:
But once I embed the function within another, it stops working.
The error is that the function CountIt is undefined. I understand that accessing CountIt from outside CountDown is difficult but in the example above - all calls to CountIt is inside the CountDown function. Does anyone know of a fix?
Code:
<script language="JavaScript1.2" type="text/javascript">
counts=10
var start=new Date();
start=Date.parse(start)/1000;
function CountIt(){
var now=new Date();
now=Date.parse(now)/1000;
var x=parseInt(counts-(now-start),10);
if(document.form1){document.form1.clock.value = x;};
if(x>0){
timerID=setTimeout("CountIt()", 100);
}
}
window.setTimeout("CountIt()",100);
</script>
But once I embed the function within another, it stops working.
Code:
<script language="JavaScript1.2" type="text/javascript">
function CountDown(counts){
var start=new Date();
start=Date.parse(start)/1000;
function CountIt(){
var now=new Date();
now=Date.parse(now)/1000;
var x=parseInt(counts-(now-start),10);
if(document.form1){document.form1.clock.value = x;};
if(x>0){
timerID=setTimeout("CountIt()", 100);
}
}
window.setTimeout("CountIt()",100);
}
CountDown(10);
</script>
The error is that the function CountIt is undefined. I understand that accessing CountIt from outside CountDown is difficult but in the example above - all calls to CountIt is inside the CountDown function. Does anyone know of a fix?