Thursday, 26 February 2015

XML Feed results - 2 input fields



Is it possible to have 2 input fields search a list from XML, but they can also depend on each other for the results...


example, input brand - Heinz


but then input item - tomato


How do i need to adapt my form/JS to do so?



function showResult(str,IdtoEdit,item) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","<?php echo SITE_URL; ?>test.php?q="+str+"&item="+item+"&id="+IdtoEdit,true);
xmlhttp.send();
}


brand <input type="text" id="brandsearch" value="" onkeyup="showResult(this.value,currCount,document.getElementById('itemsearch').value); showsearch('livesearch');" autocomplete="off" onKeyPress="return disableEnterKey(event)" />
-
item <input type="text" value="" id="itemsearch" onkeyup="showResult(getElementById('brandsearch').value,currCount,this.value); showsearch('livesearch');" autocomplete="off" onKeyPress="return disableEnterKey(event)" >

No comments:

Post a Comment