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:
<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");
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>
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
Hi,
No wrong meant. But methinks the XML Ticker (http://www.dynamicdrive.com/dynamicindex2/xmlticker.htm) 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..
This one also uses XML. Also, my code will be NS6+ compatible, while the other ticker is not.