When I load my page, no clock appears no matter what I do. I have created two buttons. If I remove the button which refers to the stopTime() function which contains clearTimeout(t); then my clock appears. If I put the button back my clock won’t work.
<body onload="getTime()">
<script>
var t;
function getTime()
{
var time = new Date();
var hour = time.getHours();
var minute = time.getMinutes();
var second = time.getSeconds();
hour = checkTime(hour);
minute = checkTime(minute);
second = checkTime(second);
var actualtime = hour + ":" + minute + ":" + second;
document.getElementById("time").innerHTML = actualtime;
t = setTimeout(function(){getTime()},1000);
}
function checkTime(i)
{
if ( i < 10 )
i = "0" + i;
return i;
}
function stopTime();
{
clearTimeout(t);
}
</script>
</body>
</html>
Thanks in advance!
You have a syntax error here:
Take out the
;at the end of yourfunction stopTime().Fixing that, your code runs fine for me.