Hello, everybody, I am a newbie here, a newbie to javascript as well. I would like to write a small clock that counts and displays like this:hour:minute:second. I got the display, yet the problem is that the clock does not count, I used the setTimeout method, I have no idea what went wrong, hope you guys can give me some hints. Thank you! Here are the codes
clock.html
<html>
<head>
<title>
Javascript Clock
</title>
<script type = "text/javascript" src = "clock.js">
</script>
</head>
<body onload = 'setTimeout("clock()",1000)'>
<div id = "time">
</div>
</body>
</html>
clock.js
var now = new Date();
var hour;
var minute;
var second;
function clock()
{
hour = now.getHours();
minute = now.getMinutes();
second = now.getSeconds();
display_time(hour,minute,second);
}
function display_time(h,m,s)
{
var time = "";
if (h < 10)
time += "0";
time += h;
time += ":";
if (m < 10)
time += "0";
time += m;
time += ":";
if (s < 10)
time += "0";
time += s;
document.getElementById("time").innerHTML = time;
}