I've been trying to get this javascript to work on the xml document (look below)... but it's just not working properly... what i'm basically trying to do is to only output cameras at a certain price entered by the user, but the script only outputs a proper result only if the value in the first <camerasSold> tag matches the user value (and if it encounters a wrong value in the following tag, it won't display anything after)... other than that, it won't work... any ideas?
-----
function makePriceTable(xmldoc, url){
var table = document.createElement("table");
table.setAttribute("border", "1");
document.body.appendChild(table);
var caption = "Camera Data from " + url;
table.createCaption( ).appendChild(document.createTextNode(caption));
var header = table.createTHead( );
var headerrow = header.insertRow(0);
headerrow.insertCell(0).appendChild(document.createTextNode("Camera ID"));
headerrow.insertCell(1).appendChild(document.createTextNode("Model"));
headerrow.insertCell(2).appendChild(document.createTextNode("UPC"));
headerrow.insertCell(3).appendChild(document.createTextNode("Price"));
headerrow.insertCell(4).appendChild(document.createTextNode("Availability"));
var mCameras = xmldoc.getElementsByTagName("camerasSold");
var uprice = document.getElementById("pricerange").value;
for(var i=0; i < mCameras.length; i++){
var iCamera = mCameras;
var mCamPrice = iCamera.getAttribute("price");
if(uprice == mCamPrice){
var id = iCamera.getAttribute("cid");
var model = iCamera.getAttribute("model");
var upc = iCamera.getAttribute("UPC");
var avail = iCamera.getAttribute("availability");
var row = table.insertRow(i+1);
row.insertCell(0).appendChild(document.createTextNode(id));
row.insertCell(1).appendChild(document.createTextNode(model));
row.insertCell(2).appendChild(document.createTextNode(upc));
row.insertCell(3).appendChild(document.createTextNode(mCamPrice));
row.insertCell(4).appendChild(document.createTextNode(avail));
}
}
}
------
<merchant name="Best Buy" phone="1-866-BEST BUY">
<mURL>www.bestbuy.ca</mURL>
<hoursOfService>monday to friday 9 to 5</hoursOfService>
<deliveryTime>2 to 3 business days</deliveryTime>
<payment>Visa</payment>
<camerasSold cid="ephoto" model="ePhoto CL50" UPC="6984861204" price="2" availability="Yes"></camerasSold>
</merchant>
<merchant name="Amazon" phone="1-800-8amazon">
<mURL>www.amazon.com</mURL>
<hoursOfService>24/7</hoursOfService>
<deliveryTime>3 to 4 business days</deliveryTime>
<payment>Visa, Mastercard, American Express</payment>
<camerasSold cid="ephoto" model="ePhoto CL50" UPC="6984861204" price="1" availability="Yes"></camerasSold>
<camerasSold cid="powershot" model="PowerShot A80" UPC="9764030714" price="2" availability="No"></camerasSold>
<camerasSold cid="finepix" model="FinePix A350" UPC="5439601927" price="1" availability="Yes"></camerasSold>
</merchant>
-----
-----
function makePriceTable(xmldoc, url){
var table = document.createElement("table");
table.setAttribute("border", "1");
document.body.appendChild(table);
var caption = "Camera Data from " + url;
table.createCaption( ).appendChild(document.createTextNode(caption));
var header = table.createTHead( );
var headerrow = header.insertRow(0);
headerrow.insertCell(0).appendChild(document.createTextNode("Camera ID"));
headerrow.insertCell(1).appendChild(document.createTextNode("Model"));
headerrow.insertCell(2).appendChild(document.createTextNode("UPC"));
headerrow.insertCell(3).appendChild(document.createTextNode("Price"));
headerrow.insertCell(4).appendChild(document.createTextNode("Availability"));
var mCameras = xmldoc.getElementsByTagName("camerasSold");
var uprice = document.getElementById("pricerange").value;
for(var i=0; i < mCameras.length; i++){
var iCamera = mCameras;
var mCamPrice = iCamera.getAttribute("price");
if(uprice == mCamPrice){
var id = iCamera.getAttribute("cid");
var model = iCamera.getAttribute("model");
var upc = iCamera.getAttribute("UPC");
var avail = iCamera.getAttribute("availability");
var row = table.insertRow(i+1);
row.insertCell(0).appendChild(document.createTextNode(id));
row.insertCell(1).appendChild(document.createTextNode(model));
row.insertCell(2).appendChild(document.createTextNode(upc));
row.insertCell(3).appendChild(document.createTextNode(mCamPrice));
row.insertCell(4).appendChild(document.createTextNode(avail));
}
}
}
------
<merchant name="Best Buy" phone="1-866-BEST BUY">
<mURL>www.bestbuy.ca</mURL>
<hoursOfService>monday to friday 9 to 5</hoursOfService>
<deliveryTime>2 to 3 business days</deliveryTime>
<payment>Visa</payment>
<camerasSold cid="ephoto" model="ePhoto CL50" UPC="6984861204" price="2" availability="Yes"></camerasSold>
</merchant>
<merchant name="Amazon" phone="1-800-8amazon">
<mURL>www.amazon.com</mURL>
<hoursOfService>24/7</hoursOfService>
<deliveryTime>3 to 4 business days</deliveryTime>
<payment>Visa, Mastercard, American Express</payment>
<camerasSold cid="ephoto" model="ePhoto CL50" UPC="6984861204" price="1" availability="Yes"></camerasSold>
<camerasSold cid="powershot" model="PowerShot A80" UPC="9764030714" price="2" availability="No"></camerasSold>
<camerasSold cid="finepix" model="FinePix A350" UPC="5439601927" price="1" availability="Yes"></camerasSold>
</merchant>
-----