JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 25th, 2012, 11:42 PM
jack13580 jack13580 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 131 jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 18 h 5 m 4 sec
Reputation Power: 75
Having trouble with a javascript script

javascript Code:
Original - javascript Code
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.   <head>
  5.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6.     <title>Javascript Power</title>
  7. <script type="text/javascript">
  8. function leadZero(x) {
  9.             if (x < 10){x = "0" + x;}
  10.                 return x;
  11.         }
  12.          function runClock() {
  13.             var today = new Date();
  14.  
  15.             var h = today.getHours();
  16.             var h1 = h;
  17.             var m = today.getMinutes();
  18.             var s = today.getSeconds();
  19.             var ampm = " AM";
  20.  
  21.             if (h >= 12) {ampm = " PM";}
  22.             if (h >= 13) {h = h - 12;}
  23.             if (h1 === 0) {h = 12;}
  24.  
  25.             h = leadZero(h)// if zero before hours is required
  26.             m = leadZero(m);
  27.             s = leadZero(s);
  28.  
  29.             document.getElementById('Clock').innerHTML = "Current Time <br />" + h + ":" +             m + ":"+ s + ampm; // delete ampm if desired
  30.  
  31.         }
  32.         function startTime() {
  33.             runClock();    // to start right away
  34.             setInterval(runClock,1000);
  35.         }
  36.         function CallDiv() {
  37.             var divTag = document.createElement("div");
  38.             divTag.id = "Clock";
  39.             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;";
  40.             document.body.appendChild(divTag);
  41.             startTime();
  42.          }
  43.  
  44. window.onload = CallDiv();
  45. </script>
  46. </head>
  47. <body> 
  48. </body>
  49. </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

Reply With Quote
  #2  
Old September 26th, 2012, 11:04 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2004
Posts: 2,222 paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 9 h 5 m 25 sec
Reputation Power: 201
when i run this code in my firefox it reports "document.body is null"

document.body.appendChild(divTag); maybe you cannot append if it is empty? however i put in randome text and that didnt work!

Reply With Quote
  #3  
Old September 26th, 2012, 02:57 PM
Beuge Beuge is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 15 Beuge User rank is Sergeant Major (2000 - 5000 Reputation Level)Beuge User rank is Sergeant Major (2000 - 5000 Reputation Level)Beuge User rank is Sergeant Major (2000 - 5000 Reputation Level)Beuge User rank is Sergeant Major (2000 - 5000 Reputation Level)Beuge User rank is Sergeant Major (2000 - 5000 Reputation Level)Beuge User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 5 h 32 m 56 sec
Reputation Power: 0
You're invoking callDiv, instead of assigning it to the onload event.

window.onload = CallDiv() should be window.onload = CallDiv;
Comments on this post
Kravvitz agrees!

Reply With Quote
  #4  
Old September 26th, 2012, 05:52 PM
jack13580 jack13580 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 131 jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 18 h 5 m 4 sec
Reputation Power: 75
wow I new it was a dumb mistake I made thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Having trouble with a javascript script

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap