nolachrymose
06-25-2002, 06:36 PM
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");
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:
<?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! :)
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");
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:
<?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! :)