Passing input value thru XML loop and return value
Posted
by Mike Dyer
on Stack Overflow
See other posts from Stack Overflow
or by Mike Dyer
Published on 2010-06-15T20:10:37Z
Indexed on
2010/06/15
20:12 UTC
Read the original article
Hit count: 165
JavaScript
|Xml
"X" is reading the form value, but it is still passing and older "var thisMarket" value.
The objective is to take a zip code via HTML form:
<form id="market" name="market" onSubmit="return validateZIP(this.zip.value);" method="get" action="">
<input type="text" name="zip" id="zip" value="zipcode" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;" style="float:left; width:100px; margin-top:5px;">
<input type="image" style="float:left; margin-top:5px; border: 0pt none ; width: 22px; height:17px;" src="images/nav/bottom/linkbar/btn_search_btn.gif" onClick="findLda();">
</form>
The script being passed thru is:
function findLda(x){
marketName = new Array();
marketURL = new Array();
zip = new Array();
zip_temp = new Array();
zipMatch = false;
var shareZip = "Shared Zips";
var thisMarket = "Market value";
xmlDoc=loadXML("/_includes/market.xml");
var Offer,node;
document.getElementById('market').innerHTML='';
for(var j=0; j<xmlDoc.getElementsByTagName('market').length; j++){
node = xmlDoc.getElementsByTagName('market')[j];
marketName.push(node.childNodes[3].textContent);
marketURL.push(node.childNodes[5].textContent);
for(var k=0; k<node.getElementsByTagName('zip').length; k++){
if(node.getElementsByTagName('zip')[k].textContent!=null){
zip_temp.push(node.getElementsByTagName('zip')[k].textContent);
}
}
zip.push(zip_temp);
zip_temp = new Array();
}
//loop the zip Array to find a match for the query Zip.
for(k=0; k<zip.length; k++){
for(m=0; m<zip[k].length; m++){
if(x == zip[k][m].toString()){
zipMatch=true;
thisMarket=marketName[k].toString();
}
}
}
alert(thisMarket);
}
The objective naturally is to take field input (A), pass it thru market.xml - initialize a loop and match a zip (B), alert the result (C).
Looking for any direction with what is existing or a completely new direction.
Thanks!
© Stack Overflow or respective owner