Web Analytics Made Easy -
StatCounter XML Ticker Cleanliness - CodingForum

Announcement

Collapse
No announcement yet.

XML Ticker Cleanliness

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • XML Ticker Cleanliness

    I am trying to rewrite the XML ticker code at http://dynamicdrive.com so that it seems clearer to the "average JS programmer." I keep getting this error:

    Line: 37
    Char: 2
    Error: 'document.getElementById(...)' is null or not an object
    I have no idea what it is talking about. I looked through my code and couldn't find any errors. I was hoping someone else could.

    xml-ticker.htm:
    Code:
    <html>
    <head>
    <title>Tickers with XML</title>
    <script type="text/javascript">
    var capable=window.ActiveXObject;
    if(capable) var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    
    var yourXML="ticking.xml" //change to path of XML file you want to use
    var interval=1000; //change to amount of milliseconds for each item to be displayed (1000 milliseconds = 1 second)
    var currentTicker=0;
    
    function loadXML(xmlFile) {
    	xmlDoc.async="false";
    	xmlDoc.load(xmlFile);
    	ticker=xmlDoc.documentElement;
    } loadXML(yourXML);
    while(!ticker==true) {}
    var tickerTape=new Array(ticker.childNodes.length);
    var topStyle=ticker.getAttribute("style");
    
    for(var i=0;i<tickerTape.length;i++) {
    	tickerTape[i]=new Object();
    	tickerTape[i].text=ticker.childNodes(i).childNodes(0);
    	tickerTape[i].style=ticker.childNodes(i).getAttribute("style");
    	tickerTape[i].href=ticker.childNodes(i).getAttribute("href");
    }
    
    function mkTicker(appendEl) {
    	var tickEl=document.createElement("div");
    	tickEl.setAttribute("style",topStyle);
    	tickEl.setAttribute("id","ticker");
    	appendEl.appendChild(tickEl);
    } 
    
    function startTicker() {
    	var display='<a href="'+tickerTape[currentTicker].href+'" style="'+tickerTape[currentTicker].style+'">'+tickerTape[currentTicker].text+'</a>';
    	document.getElementById("ticker").innerHTML=display;
    
    	currentTicker++;
    	if(currentTicker>=tickerTape.length) currentTicker=0;
    	setTimeout(startTicker,interval);
    } window.onload=function() {
    startTicker();
    var tickerContainer=document.body //change to element that will have the ticker appended to it
    mkTicker(tickerContainer);
    };
    </script>
    </head>
    <body>
    <div id="tickContain"></div>
    <script type="text/javascript">
    mkTicker(tickerContainer);
    </script>
    </body>
    </html>
    ticking.xml:
    Code:
    <?xml version="1.0"?>
    <ticks style="background-color:yellow;text-align:center;border:solid red 1px;">
    	<tick style="color:red;text-decoration:none;" href="http://dynamicdrive.com">Dynamic Drive</tick>
    	<tick style="color:red;text-decoration:none;" href="http://javascriptkit.com">JavaScript Kit</tick>
    </ticks>
    Happy coding!
    Last edited by nolachrymose; Jun 25, 2002, 12:43 PM.

  • #2
    The only id I'm seeing in that document is:
    "tickContain"

    In the DIV, yet you are using document.getElementById('ticker') which returns undefined if no nodes are found... or maybe I'm blind?

    BTW, if you're rewriting the script, you might as well make it work in NS6+ too:

    http://www.xs4all.nl/~ppk/js/importxml.html
    jasonkarldavis.com

    Comment


    • #3
      Hi,

      No wrong meant. But methinks the XML Ticker is easy to understand for the "Average JS Programmer". Infact I think the fact that XML has been used makes things easier to edit.

      Well, could you tell me what modifications you intend to make?
      Could you propose some modifications so that I could also try..
      Scripting | JavaScripts | PerlScripts | Python Scripts | Articles | My Journal

      Comment


      • #4
        This one also uses XML. Also, my code will be NS6+ compatible, while the other ticker is not.

        Happy coding!

        Comment

        Working...
        X