Hello,
When I try to insert this line of code into my script, Firefox refuses to
render. Could someone explain to me why that is?
if (x[i].firstChild.firstChild.nodeValue==productID) {
some code
}
full code listed below:
HTML BODY
===============================
<div id="writeroot"></div>
<script type="text/javascript">
importXML("prices.xml", priceTable, "kenko", "L37 Super PRO");
</script>
JAVASCRIPT
===============================
function importXML(xmlFile, xmlDisplay, para1, para2) {
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) xmlDisplay(para1, para2);
}
} else if (document.implementation &&
document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = function() {
xmlDisplay(para1, para2);
}
} else {
alert('Sorry, your browser doesn't support XML scripting');
return;
}
xmlDoc.async = "false";
xmlDoc.load(xmlFile);
}
function priceTable(productCat, productID) {
var pCat = xmlDoc.getElementsByTagName(productCat);
var x = pCat[0].getElementsByTagName("item");
var newTable = document.createElement("table");
newTable.setAttribute("border",1);
var tableBody = document.createElement("tbody");
newTable.appendChild(tableBody);
var row = document.createElement("tr");
var emptyCell = document.createElement("th");
row.appendChild(emptyCell);
for (j=3; j<x[0].childNodes.length; j++) {
if (x[0].childNodes[j].nodeType != 1) continue;
var container = document.createElement("th");
var theData = document.createTextNode(x[0].childNodes
[j].nodeName.substring(1));
container.appendChild(theData);
row.appendChild(container);
}
tableBody.appendChild(row);
for (i=0; i<x.length; i++) {
var row = document.createElement("tr");
// if (x[i].firstChild.firstChild.nodeValue==productID) {
if (window.ActiveXObject) {
row.style.setAttribute("cssText", "background-color:
#cfc;");
} else if (document.implementation &&
document.implementation.createDocument) {
row.setAttribute("style", "background-color:
#cfc;");
}
// }
var nameCell = document.createElement("th");
var productName = document.createTextNode(x[i].childNodes
[1].firstChild.nodeValue);
nameCell.appendChild(productName);
row.appendChild(nameCell);
for (j=3; j<x[i].childNodes.length; j++) {
if (x[i].childNodes[j].nodeType != 1) continue;
var priceCell = document.createElement("td");
var priceData = document.createTextNode(x[i].childNodes
[j].firstChild==null ? "" : x[i].childNodes[j].firstChild.nodeValue);
priceCell.appendChild(priceData);
row.appendChild(priceCell);
}
tableBody.appendChild(row);
}
document.getElementById("writeroot").appendChild(n ewTable);
}
XML
====================
<products>
<lens>
<uv>
<item>
<en>kenko</en>
<gb>L37</gb>
<description>
</description>
<d49mm>132</d49mm>
<d52mm>143</d52mm>
<d55mm>160</d55mm>
<d58mm>170</d58mm>
<d62mm>210</d62mm>
<d67mm>245</d67mm>
<d72mm>285</d72mm>
<d77mm>320</d77mm>
<d82mm>425</d82mm>
<d86mm>715</d86mm>
</item>
</uv>
</lens>
</products>