
September 25th, 2012, 11:42 PM
|
|
|
|
Having trouble with a javascript script
javascript Code:
Original
- javascript Code |
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Javascript Power</title> <script type="text/javascript"> function leadZero(x) { if (x < 10){x = "0" + x;} return x; } function runClock() { var today = new Date(); var h = today.getHours(); var h1 = h; var m = today.getMinutes(); var s = today.getSeconds(); var ampm = " AM"; if (h >= 12) {ampm = " PM";} if (h >= 13) {h = h - 12;} if (h1 === 0) {h = 12;} h = leadZero(h); // if zero before hours is required m = leadZero(m); s = leadZero(s); document.getElementById('Clock').innerHTML = "Current Time <br />" + h + ":" + m + ":"+ s + ampm; // delete ampm if desired } function startTime() { runClock(); // to start right away setInterval(runClock,1000); } function CallDiv() { var divTag = document.createElement("div"); divTag.id = "Clock"; divTag.style.cssText = "display:block;font-family:Arial,Helvetica,sans-serif;font-weight:bold;font-size:10pt;line-height:100%; text-align: center;padding-top:10px;"; document.body.appendChild(divTag); startTime(); } window.onload = CallDiv(); </script> </head> <body> </body> </html>
for some reason my script isn't working even though the syntax is correct
and for some reason it works on my jsfiddle but not on a live page
http://jsfiddle.net/jack13580/ZdXCP/
and live page http://the-test.comoj.com/files/javascript-power.html
|