document.getElementbyID('TICKER') has no properties

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RommelTJ
    New Member
    • Aug 2007
    • 8

    document.getElementbyID('TICKER') has no properties

    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.getEle mentById("TICKE R") has no properties
    TICKER_CONTENT = document.getEle mentById("TICKE R").innerHTM L;
    Here is the complete script:
    [code=javascript]
    // WebTicker by Mioplanet
    3// www.mioplanet.c om
    4
    5TICKER_CONTENT = document.getEle mentById("TICKE R").innerHTM L;
    6
    7TICKER_RIGHTTO LEFT = false;
    8TICKER_SPEED = 1;
    9TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
    10TICKER_PAUSED = false;
    11
    12ticker_start( );
    13
    14function ticker_start() {
    15 var tickerSupported = false;
    16 TICKER_WIDTH = document.getEle mentById("TICKE R").style.width ;
    17 var img = "<img src=ticker_spac e.gif width="+TICKER_ WIDTH+" height=0>";
    18
    19 // Firefox
    20 if (navigator.user Agent.indexOf(" Firefox")!=-1 || navigator.userA gent.indexOf("S afari")!=-1) {
    21 document.getEle mentById("TICKE R").innerHTM L = "<TABLE cellspacing='0' cellpadding='0' width='100%'><T R><TD nowrap='nowrap' >"+img+"<SPA N style='"+TICKER _STYLE+"' ID='TICKER_BODY ' width='100%'>&n bsp;</SPAN>"+img+"</TD></TR></TABLE>";
    22 tickerSupported = true;
    23 }
    24 // IE
    25 if (navigator.user Agent.indexOf(" MSIE")!=-1 && navigator.userA gent.indexOf("O pera")==-1) {
    26 document.getEle mentById("TICKE R").innerHTM L = "<DIV nowrap='nowrap' style='width:10 0%;'>"+img+"<SP AN style='"+TICKER _STYLE+"' ID='TICKER_BODY ' width='100%'></SPAN>"+img+"</DIV>";
    27 tickerSupported = true;
    28 }
    29 if(!tickerSuppo rted) document.getEle mentById("TICKE R").outerHTM L = ""; else {
    30 document.getEle mentById("TICKE R").scrollLe ft = TICKER_RIGHTTOL EFT ? document.getEle mentById("TICKE R").scrollWi dth - document.getEle mentById("TICKE R").offsetWi dth : 0;
    31 document.getEle mentById("TICKE R_BODY").innerH TML = TICKER_CONTENT;
    32 document.getEle mentById("TICKE R").style.displ ay="block";
    33 TICKER_tick();
    34 }
    35}
    36
    37function TICKER_tick() {
    38 if(!TICKER_PAUS ED) document.getEle mentById("TICKE R").scrollLe ft += TICKER_SPEED * (TICKER_RIGHTTO LEFT ? -1 : 1);
    39 if(TICKER_RIGHT TOLEFT && document.getEle mentById("TICKE R").scrollLe ft <= 0) document.getEle mentById("TICKE R").scrollLe ft = document.getEle mentById("TICKE R").scrollWi dth - document.getEle mentById("TICKE R").offsetWidth ;
    40 if(!TICKER_RIGH TTOLEFT && document.getEle mentById("TICKE R").scrollLe ft >= document.getEle mentById("TICKE R").scrollWi dth - document.getEle mentById("TICKE R").offsetWidth ) document.getEle mentById("TICKE R").scrollLe ft = 0;
    41 window.setTimeo ut("TICKER_tick ()", 30);
    42}
    43[/code]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    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?

    Comment

    • RommelTJ
      New Member
      • Aug 2007
      • 8

      #3
      Originally posted by pbmods
      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.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        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

        Comment

        • RommelTJ
          New Member
          • Aug 2007
          • 8

          #5
          more info

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

          [CODE=html] <table border="0" width="266">
          <tr>
          <td width="5%"><p>< script type="text/javascript" src="webticker_ lib.js" language="javas cript"></script>
          </p>



          <!-- TICKER IS HERE -->
          <DIV ID="TICKER" STYLE="display: none; border-top:1px solid #CCCCCC; border-bottom:1px solid #CCCCCC; overflow:hidden ; background-color:#FFFFFF; width:250px" onmouseover="TI CKER_PAUSED=tru e" onmouseout="TIC KER_PAUSED=fals e">



          <span style='backgrou nd-color:#0088FF;' > &nbsp; &nbsp; <B><font color=#ffffff> News and Announcements:</font></a></B>&nbsp; &nbsp; </span>
          <span style='backgrou nd-color:#006633;' > &nbsp; &nbsp;
          <B><A href="/news/recent_news.php "><font color=#ffffff> Read our Latest News Report: July 2007</font></a></B>&nbsp; &nbsp; </span>
          <span style='backgrou nd-color:#CCCCCC;' > &nbsp; &nbsp;
          <B><A href="/events/seguridad_publi ca_y_reforma_pe nal_en_mexico.p hp"><font color=#ffffff> Recent Event: Seguridad Publica y Reforma Penal en Mexico</font></a></B>&nbsp; &nbsp; </span>
          <span style='backgrou nd-color:#CC0000;' > &nbsp; &nbsp;
          <B><A href="/events/binational_foru m_on_alternativ e_criminal_just ice.php"><font color=#ffffff> Recent Event: Binational Forum on Alternative Criminal Justice</font></a></B>&nbsp; &nbsp; </span>&nbsp;
          <span style='backgrou nd-color:#0088FF;' > &nbsp; &nbsp;
          <B><A href="http://www.justiceinme xico.org/search/index.php"><fon t color=#ffffff> Search</font></a></B>&nbsp; &nbsp; </span>
          <span style='backgrou nd-color:#006633;' > &nbsp; &nbsp;
          <B><A href="http://www.justiceinme xico.org/contact/index.php"><fon t color=#ffffff> Contact us/Subscribe</font></a></B>&nbsp; &nbsp; </span>
          <span style='backgrou nd-color:#CCCCCC;' > &nbsp; &nbsp;
          <B><A href="http://www.sandiego.ed u/tbi/"><font color=#ffffff> USD: Trans-Border Institute</font></a></B>&nbsp; &nbsp; </span> <span style='backgrou nd-color:#FFFFFF;' > &nbsp; &nbsp;
          <B><A href="http://www.mioplanet.c om/rsc/newsticker_java script.htm" target="Mio">Sc rolling News Ticker</A>
          by <a href="http://www.mioplanet.c om">Mioplanet </a></B>&nbsp;&nbsp; </DIV>

          <script type="text/javascript" src="webticker_ lib.js" language="javas cript"></script> </td>
          </tr>
          </table> </td>
          </tr>
          </table> [/CODE]

          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.
          Last edited by RommelTJ; Aug 20 '07, 06:54 PM. Reason: emphasis

          Comment

          • RommelTJ
            New Member
            • Aug 2007
            • 8

            #6
            Help would be appreciated.

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Heya, Rommel.

              Try this. Remove this line (I think it's line 12 or so):
              [code=javascript]
              ticker_start();
              [/code]

              And then change your HTML slightly:
              [code=html]
              <body onload="ticker_ start();">
              [/code]

              Comment

              • RommelTJ
                New Member
                • Aug 2007
                • 8

                #8
                Originally posted by pbmods
                Heya, Rommel.

                Try this. Remove this line (I think it's line 12 or so):
                [code=javascript]
                ticker_start();
                [/code]

                And then change your HTML slightly:
                [code=html]
                <body onload="ticker_ start();">
                [/code]
                Thanks, but where should I put the HTML code?

                Comment

                • pbmods
                  Recognized Expert Expert
                  • Apr 2007
                  • 5821

                  #9
                  Heya, Rommel.

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

                  Comment

                  • RommelTJ
                    New Member
                    • Aug 2007
                    • 8

                    #10
                    Originally posted by pbmods
                    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.

                    Comment

                    • RommelTJ
                      New Member
                      • Aug 2007
                      • 8

                      #11
                      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.

                      Comment

                      • pbmods
                        Recognized Expert Expert
                        • Apr 2007
                        • 5821

                        #12
                        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 :)

                        Comment

                        • JamieHowarth0
                          Recognized Expert Contributor
                          • May 2007
                          • 537

                          #13
                          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

                          Comment

                          • RommelTJ
                            New Member
                            • Aug 2007
                            • 8

                            #14
                            Originally posted by medicineworker
                            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.

                            Comment

                            Working...