By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 3,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

document.getElementbyID('TICKER') has no properties

P: 8
Hi,

My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the internet.

When I run Firebug on it, it says:

document.getElementById("TICKER") has no properties
TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
Here is the complete script:
Expand|Select|Wrap|Line Numbers
  1. // WebTicker by Mioplanet
  2. 3// www.mioplanet.com
  3. 4
  4. 5TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
  5. 6
  6. 7TICKER_RIGHTTOLEFT = false;
  7. 8TICKER_SPEED = 1;
  8. 9TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
  9. 10TICKER_PAUSED = false;
  10. 11
  11. 12ticker_start();
  12. 13
  13. 14function ticker_start() {
  14. 15 var tickerSupported = false;
  15. 16 TICKER_WIDTH = document.getElementById("TICKER").style.width;
  16. 17 var img = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>";
  17. 18
  18. 19 // Firefox
  19. 20 if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
  20. 21 document.getElementById("TICKER").innerHTML = "<TABLE cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
  21. 22 tickerSupported = true;
  22. 23 }
  23. 24 // IE
  24. 25 if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
  25. 26 document.getElementById("TICKER").innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>";
  26. 27 tickerSupported = true;
  27. 28 }
  28. 29 if(!tickerSupported) document.getElementById("TICKER").outerHTML = ""; else {
  29. 30 document.getElementById("TICKER").scrollLeft = TICKER_RIGHTTOLEFT ? document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth : 0;
  30. 31 document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
  31. 32 document.getElementById("TICKER").style.display="block";
  32. 33 TICKER_tick();
  33. 34 }
  34. 35}
  35. 36
  36. 37function TICKER_tick() {
  37. 38 if(!TICKER_PAUSED) document.getElementById("TICKER").scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
  38. 39 if(TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft <= 0) document.getElementById("TICKER").scrollLeft = document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth;
  39. 40 if(!TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft >= document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth) document.getElementById("TICKER").scrollLeft = 0;
  40. 41 window.setTimeout("TICKER_tick()", 30);
  41. 42}
  42. 43
Aug 20 '07 #1
Share this Question
Share on Google+
13 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Rommel. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

Does the TICKER element exist at the time that the browser evaluates this JavaScript?
Aug 20 '07 #2

P: 8
Heya, Rommel. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

Does the TICKER element exist at the time that the browser evaluates this JavaScript?
Sorry about that. I apologize for not using the code tags. I read the forum guidelines, but I didn't read the Reply guidelines. I can see them now.

I don't know. I'm a noobie at this. I just copy pasted the free javascript ticker to my website and it messed it up on IE, but not on Firefox.

How can I check if the TICKER element exists at the time that the browser evaluates it?

I think the answer is no, because Firebug doesn't detect an error immediately, it takes about 2 minutes to come up with the error. Sorry for sounding completely clueless, but I am.

By the way, I used the search bar first and it seems that many people hve this problem. However, since I don't know js I can't fix it.
Aug 20 '07 #3

gits
Expert Mod 5K+
P: 5,333
hi ...

there has to be a html-element with the id="TICKER" at your page ... assure that, may be you should refer to the page from where you copied the script.

when do you call the script ... during the load-time of the page or in the body onload event? you should always use the onload-event of the body since the dom of your page is ready to use at this time.

kind regards
Aug 20 '07 #4

P: 8
It's inside the body of the html inside a table. Here is the html:

Expand|Select|Wrap|Line Numbers
  1.  <table border="0" width="266">
  2.         <tr>
  3.         <td width="5%"><p><script type="text/javascript" src="webticker_lib.js" language="javascript"></script>
  4.         </p>
  5.  
  6.  
  7.  
  8.         <!-- TICKER IS HERE -->
  9.         <DIV ID="TICKER" STYLE="display:none; border-top:1px solid #CCCCCC; border-bottom:1px solid #CCCCCC; overflow:hidden; background-color:#FFFFFF; width:250px" onmouseover="TICKER_PAUSED=true" onmouseout="TICKER_PAUSED=false">
  10.  
  11.  
  12.  
  13.         <span style='background-color:#0088FF;'> &nbsp; &nbsp; <B><font color=#ffffff> News and Announcements:</font></a></B>&nbsp; &nbsp; </span>
  14.         <span style='background-color:#006633;'> &nbsp; &nbsp; 
  15.             <B><A href="/news/recent_news.php"><font color=#ffffff> Read our Latest News Report: July 2007</font></a></B>&nbsp; &nbsp; </span>
  16.         <span style='background-color:#CCCCCC;'> &nbsp; &nbsp; 
  17.             <B><A href="/events/seguridad_publica_y_reforma_penal_en_mexico.php"><font color=#ffffff> Recent Event: Seguridad Publica y Reforma Penal en Mexico</font></a></B>&nbsp; &nbsp; </span>
  18.         <span style='background-color:#CC0000;'> &nbsp; &nbsp; 
  19.             <B><A href="/events/binational_forum_on_alternative_criminal_justice.php"><font color=#ffffff> Recent Event: Binational Forum on Alternative Criminal Justice</font></a></B>&nbsp; &nbsp; </span>&nbsp; 
  20.         <span style='background-color:#0088FF;'> &nbsp; &nbsp; 
  21.             <B><A href="http://www.justiceinmexico.org/search/index.php"><font color=#ffffff> Search</font></a></B>&nbsp; &nbsp; </span>
  22.         <span style='background-color:#006633;'> &nbsp; &nbsp; 
  23.             <B><A href="http://www.justiceinmexico.org/contact/index.php"><font color=#ffffff> Contact us/Subscribe</font></a></B>&nbsp; &nbsp; </span>
  24.         <span style='background-color:#CCCCCC;'> &nbsp; &nbsp; 
  25.             <B><A href="http://www.sandiego.edu/tbi/"><font color=#ffffff> USD: Trans-Border Institute</font></a></B>&nbsp; &nbsp; </span>        <span style='background-color:#FFFFFF;'> &nbsp; &nbsp;
  26.         <B><A href="http://www.mioplanet.com/rsc/newsticker_javascript.htm" target="Mio">Scrolling News Ticker</A>
  27. by <a href="http://www.mioplanet.com">Mioplanet</a></B>&nbsp;&nbsp;    </DIV>
  28.  
  29.     <script type="text/javascript" src="webticker_lib.js" language="javascript"></script>        </td>
  30.     </tr>
  31.     </table>    </td>
  32.   </tr>
  33. </table> 
Thank you for your help. It is much appreciated. I've been trying to fix this for weeks.

Note: for some reason, my post suddenly put all tags in bold.
Aug 20 '07 #5

P: 8
Help would be appreciated.
Aug 21 '07 #6

pbmods
Expert 5K+
P: 5,821
Heya, Rommel.

Try this. Remove this line (I think it's line 12 or so):
Expand|Select|Wrap|Line Numbers
  1. ticker_start();
  2.  
And then change your HTML slightly:
Expand|Select|Wrap|Line Numbers
  1. <body onload="ticker_start();">
  2.  
Aug 21 '07 #7

P: 8
Heya, Rommel.

Try this. Remove this line (I think it's line 12 or so):
Expand|Select|Wrap|Line Numbers
  1. ticker_start();
  2.  
And then change your HTML slightly:
Expand|Select|Wrap|Line Numbers
  1. <body onload="ticker_start();">
  2.  
Thanks, but where should I put the HTML code?
Aug 22 '07 #8

pbmods
Expert 5K+
P: 5,821
Heya, Rommel.

Replace the body declaration ('<body>') in your code with the new code. There is always only one body tag per HTML file.
Aug 22 '07 #9

P: 8
Heya, Rommel.

Replace the body declaration ('<body>') in your code with the new code. There is always only one body tag per HTML file.
Oh. Duh.

I already load the common images there and it's a relatively large list under the parenthesis. I put a comma and added the code you gave me, but it still shows up wrong.

Actually, Firebug stopped detecting an error, but IE says there is an error in loading an object in line 6 Char 1. I went to line 6, but those are only common pictures and they were working before.

In any case, the site still looks bad on IE but good on firefox.
Aug 23 '07 #10

P: 8
Sorry for double posting, but this makes me irritated.

I decided to take out the webticker from the site, and the site still looks wrong. So there is no problem with the javascript.......It's probably with the html or php.

Sorry to bother you guys.
Aug 23 '07 #11

pbmods
Expert 5K+
P: 5,821
Heya, Rommel.

Try posting over at the HTML/CSS forum. Once you get the display issues hammered out, come on back and let's get the ticker working.

Good luck with your project, and if you ever need anything, post back anytime :)
Aug 23 '07 #12

codegecko
Expert 100+
P: 533
Hi Rommel,

My thoughts are that the JS reference isn't placed in the head section of your site, which is where I would normally put a reference to an external JS file.
Not only that, but check out your markup validation here - it shows more than 300 errors with XHTML Transitional and I had to over-ride on character encoding to iso-8859-1, which is a massive problem.

This could be why it isn't quite parsing correctly - in an ideal world, Javascript does like to deal with clean, compliant code.

My suggestion - clean up your XHTML big-time, then if the script still isn't working, it's one thing we know can't be wrong with it - messy code.

All the best,

medicineworker
Aug 23 '07 #13

P: 8
Hi Rommel,
......My suggestion - clean up your XHTML big-time, then if the script still isn't working, it's one thing we know can't be wrong with it - messy code.

All the best,

medicineworker
Thank you very much, I cleaned up my code down to 66 errors. I will iron those out tomorrow.
I still get the getelementbyID has no properties error, so I don't think it's the code.

At least everything is displaying properly at the moment, so I'll leave it at that, and if something arises with the html, I'll post it in the proper forum.

Thank you again.
Aug 24 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.