User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 403,515 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,922 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 598 | Replies: 2 | Solved
Reply
Join Date: Aug 2007
Posts: 2
Reputation: pakoppan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pakoppan pakoppan is offline Offline
Newbie Poster

TypeError in an otherwise working script.

  #1  
Jul 1st, 2008
Hello,

I have the following script that used to work with FF2. Now I get under FF3:

TypeError: document.getElementByID('content') is null

SCRIPT:
  1. function Sounding(){
  2. var yr = "08";
  3. var myArray = new Array();
  4. myArray[0] = new Date() ;
  5. var mes = (myArray[0].getMonth() );
  6. if (mes.length = 2)
  7. {
  8. mes = mes +1;
  9. mes = "0"+mes;
  10. }
  11. var day = (myArray[0].getDate() );
  12.  
  13. if (day.length = 1)
  14. {
  15. day = "0" + day;
  16.  
  17. }
  18. var align= '<p align="center">';
  19. var img = '<img src="';
  20. var http = 'http://www.spc.noaa.gov/exper/soundings';
  21. var slash = '\/';
  22. var obs = '12_OBS/OAX.gif">';
  23. var theString=align+img+http+slash+yr+mes+day+obs+"</p>";
  24. alert(theString);
  25. document.getElementById('content').innerHTML=theString;
  26. }
  27. window.onload=Sounding;

EXPLANATION:

The code created should look like this:

<p align="center"><img src="http://www.spc.noaa.gov/exper/soundings/08070112_OBS/OAX.gif"></p>

is displayed correctly (alert) but it ends up issuing the error message above (in red font).


Could anyone tell me what is wrong here? I can't find the problem.


OBSERVATION:

the part where it reads 080701 changes daily(obvious). But if in a test no results are shown and no message is issued, the try to change 12OBS to 00OBS.

The result should be a very "weird" looking meteorological stuff.


Thanks for any help
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 458
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 68
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: TypeError in an otherwise working script.

  #2  
Jul 1st, 2008
Well the error is generated when you try to get an element that doesn't exist so the simple question is, does the element with the ID "content" exist on the page before you make that call?
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Join Date: Aug 2007
Posts: 2
Reputation: pakoppan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pakoppan pakoppan is offline Offline
Newbie Poster

Re: TypeError in an otherwise working script.

  #3  
Jul 2nd, 2008
ShawnCplus,

Thank you or your quick reply.

Now, <div id=content"></div> WAS indeed missing and I missed this probably because of the many other changes I did in that page.

Now, this is not part of the problem but it is interesting to notice that if I call the page from within Dreamweaver with file>Preview in Browser, IE7 brings the page correctly.

Using FF3, the script is not executed for some reason (it was under FF2). I get no alert message and the graph doesn't show up.

I have to load the page into the web server and then both browsers work fine.

Anyway, that was a stupid mistake of mine and thanks for placing the correct question to me in your reply. That was great.

Thank you again

Have a nice 4th of July
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 1:00 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC