Was wondering where I am going wrong with this snippet of code, basically the startTime() only gets run once and thats it so the clock doesnt update. Can anyone advise how I can fix this?
JS
function startTime(){
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500);
}
function checkTime(i){
if (i<10)
{
i="0" + i;
}
return i;
}
HTML
<body onload="startTime()">
<p>Date</p>
<?php echo date("d/m/y"); ?>
<p>Time</p>
<div id="txt"></div>
Link http://bit.ly/IC9ohX