xcandiottix Posted July 23, 2010 Share Posted July 23, 2010 Okay, I am creating a search form. There are two search fields.. possibly more in the future so my solution has to be scalable. <form name="searchc" action="" onkeyup="update()"> <input name="firstName" type="text" size="30" /> First Name<br /> <input name="lastName" type="text" size="30" /> Last Name<br /> </form> <script type="text/javascript"> function update() { showCategory('firstName',document.searchc.firstName.value); showCategory('lastName',document.searchc.lastName.value); } </script> <script type="text/javascript"> function showCategory(name,str){ if (str==""){ document.getElementById("PeopleResults").innerHTML=""; 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("PeopleResults").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","http://www.site.com/ajax/peoplesearchcriteria.php?"+name+"="+str,true); xmlhttp.send(); } This currently sends EITHER a first name or a last name search to peoplesearchcriteria.php. I need to send both. As I said since this is scalable I want to use an array like this: // make an array for each form field inputs = document.searchc.elements; numberOfInputs = count(inputs); for(i=0; i <=numberOfInputs; i++){ feild+i=document.searchc.element[i].value } // add each field+i to a string .. how? if (str==""){ document.getElementById("PeopleResults").innerHTML=""; 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("PeopleResults").innerHTML=xmlhttp.responseText; } } //append this URL with array of field data sets xmlhttp.open("GET","http://www.site.com/ajax/peoplesearchcriteria.php?("+name+"="+str)xeach field,true); xmlhttp.send(); } So the end result upon entering a first name would be: http://www.site.com/ajax/peoplesearchcriteria.php?field0=Keith Just last name: http://www.site.com/ajax/peoplesearchcriteria.php?field1=Candiotti Or Both: http://www.site.com/ajax/peoplesearchcriteria.php?field0=Keith&&field1=Candiotti ANY help on this one would be most awesome Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.