jamiller
04-20-2007, 02:37 PM
So I'm using XML in my html doc to populate some fields with data.
The problem is I don't want to create document.getElementById("IDNAME").innerHTML=xmlDoc.getElementsByTagName("XMLNODENAME")[0].childNodes[0].nodeValue; for each span id I have so I have decided to make a for loop. The problem with the code I have now is that it only populates the first id.
var xmlDoc;
function loadXML() {
// XML Windows parser
if(window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("test.xml")
getXML();
// Firefox XML parser
} else if (document.implementation && document.implementation.createDocument) {
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("test.xml")
xmlDoc.onload=getXML;
}
}
function getXML() {
// 30 is the number of nodes; TT is the span id (plus a number); and item is the XML node (plus a number)
for(var i=1; i<=30; i++) {
document.getElementById('TT'+i).innerHTML = xmlDoc.getElementsByTagName('item'+i)[i-1].childNodes[i-1].nodeValue;
}
}
Like I said, span id TT1 populates no problem, but spans 2-30 do not. Any suggestions? I cannot figure this out.
The problem is I don't want to create document.getElementById("IDNAME").innerHTML=xmlDoc.getElementsByTagName("XMLNODENAME")[0].childNodes[0].nodeValue; for each span id I have so I have decided to make a for loop. The problem with the code I have now is that it only populates the first id.
var xmlDoc;
function loadXML() {
// XML Windows parser
if(window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("test.xml")
getXML();
// Firefox XML parser
} else if (document.implementation && document.implementation.createDocument) {
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("test.xml")
xmlDoc.onload=getXML;
}
}
function getXML() {
// 30 is the number of nodes; TT is the span id (plus a number); and item is the XML node (plus a number)
for(var i=1; i<=30; i++) {
document.getElementById('TT'+i).innerHTML = xmlDoc.getElementsByTagName('item'+i)[i-1].childNodes[i-1].nodeValue;
}
}
Like I said, span id TT1 populates no problem, but spans 2-30 do not. Any suggestions? I cannot figure this out.