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.fir stChild.nodeVal ue==productID) {
some code
}
full code listed below:
HTML BODY
=============== =============== =
<div id="writeroot"> </div>
<script type="text/javascript">
importXML("pric es.xml", priceTable, "kenko", "L37 Super PRO");
</script>
JAVASCRIPT
=============== =============== =
function importXML(xmlFi le, xmlDisplay, para1, para2) {
if (window.ActiveX Object) {
xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.onreadys tatechange = function () {
if (xmlDoc.readySt ate == 4) xmlDisplay(para 1, para2);
}
} else if (document.imple mentation &&
document.implem entation.create Document) {
xmlDoc = document.implem entation.create Document("", "", null);
xmlDoc.onload = function() {
xmlDisplay(para 1, para2);
}
} else {
alert('Sorry, your browser doesn't support XML scripting');
return;
}
xmlDoc.async = "false";
xmlDoc.load(xml File);
}
function priceTable(prod uctCat, productID) {
var pCat = xmlDoc.getEleme ntsByTagName(pr oductCat);
var x = pCat[0].getElementsByT agName("item");
var newTable = document.create Element("table" );
newTable.setAtt ribute("border" ,1);
var tableBody = document.create Element("tbody" );
newTable.append Child(tableBody );
var row = document.create Element("tr");
var emptyCell = document.create Element("th");
row.appendChild (emptyCell);
for (j=3; j<x[0].childNodes.len gth; j++) {
if (x[0].childNodes[j].nodeType != 1) continue;
var container = document.create Element("th");
var theData = document.create TextNode(x[0].childNodes
[j].nodeName.subst ring(1));
container.appen dChild(theData) ;
row.appendChild (container);
}
tableBody.appen dChild(row);
for (i=0; i<x.length; i++) {
var row = document.create Element("tr");
// if (x[i].firstChild.fir stChild.nodeVal ue==productID) {
if (window.ActiveX Object) {
row.style.setAt tribute("cssTex t", "background-color:
#cfc;");
} else if (document.imple mentation &&
document.implem entation.create Document) {
row.setAttribut e("style", "background-color:
#cfc;");
}
// }
var nameCell = document.create Element("th");
var productName = document.create TextNode(x[i].childNodes
[1].firstChild.nod eValue);
nameCell.append Child(productNa me);
row.appendChild (nameCell);
for (j=3; j<x[i].childNodes.len gth; j++) {
if (x[i].childNodes[j].nodeType != 1) continue;
var priceCell = document.create Element("td");
var priceData = document.create TextNode(x[i].childNodes
[j].firstChild==nu ll ? "" : x[i].childNodes[j].firstChild.nod eValue);
priceCell.appen dChild(priceDat a);
row.appendChild (priceCell);
}
tableBody.appen dChild(row);
}
document.getEle mentById("write root").appendCh ild(newTable);
}
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>