I want to extract a value from my hidden inputbox, by using javascript, but sometimes i am getting a "undefined" error and sometimes no output. when i did
alert(document.getElementById('hhh').value);
from inside a printIt() function i get the output. but i think somehow it is not going in to "var a", and also
var a =22;
works if i remove the
var a =document.getElementById('hhh').value;
in below code.
<script type="text/javascript">
var a =document.getElementById('hhh').value;
function startTime()
{
document.getElementById('txt').innerHTML=a;
a=a-1;
t=setTimeout('startTime()',600);
}
</script>
<body onLoad="startTime()">
<form name="form1" id="form11" method="post" action="">
<input type="hidden" id="hhh" name="time" value="11" />
</form>
<div id="txt"></div>
</body>
Any help would be appreciated. Thanks.
setTimeout, pass functions instead. And don't usesetTimeoutfor something you want to keep happening, usesetIntervalinstead.setInterval(startTime, 600);