Saturday, 15 June 2013

html - Javascript clock only works with embeddd code? how come? -



html - Javascript clock only works with embeddd code? how come? -

ok. learning how create clock. went w3schools check out code. want mess around armed forces time , forth. cant seem code work. when take code , set in js file. not code running. if set in html embedded works? doing wrong here?

function starttime() { var today=new date(); var h=today.gethours(); var m=today.getminutes(); var s=today.getseconds(); // add together 0 in front end of numbers<10 m=checktime(m); s=checktime(s); document.getelementbyid('txt').innerhtml=h+":"+m+":"+s; t=settimeout(function(){starttime()},500); } function checktime(i) { if (i<10) { i="0" + i; } homecoming i; }

html follows

<!doctype html> <html> <head> <meta charset="utf-8"> <title>city clock</title> <link rel="stylesheet" href="clock.css"> </head> <body> <h1> austen's clock</h1> </head> <body onload="starttime()"> <div id="txt"></div> </body> </html> <script type="text/javascript" src="clock.js"></script> </body> </html>

move <script type="text/javascript" src="clock.js"></script> head of document

or

rewrite code this

window.onload = function starttime() {.....

javascript html

No comments:

Post a Comment