justinjkiss Posted November 14, 2011 Share Posted November 14, 2011 Does anybody have a chunk of code i could use? Im struggling finding something to pass 2 values from 2 select boxes to a php form and return a result. Sounds so easy but i cant make it work and im a noob at javascript/ajax. I have got it to send one of the 2 values but the other value that gets sent is undefined. Thanks, Justin Quote Link to comment https://forums.phpfreaks.com/topic/251137-passing-multiple-values-with-ajax/ Share on other sites More sharing options...
requinix Posted November 15, 2011 Share Posted November 15, 2011 You're having a problem with some code, right? How about you post it so we can see what's wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/251137-passing-multiple-values-with-ajax/#findComment-1288183 Share on other sites More sharing options...
justinjkiss Posted November 15, 2011 Author Share Posted November 15, 2011 AJAX <script> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getfunit(modelId,locationId) { var strURL="getfunit.php?model="+document.fparts.model.vaule+"&location="+document.fparts.location.value; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('funitdiv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("POST", strURL, true); req.send(null); } } </script> form code <form name="fparts" action="<?=$_SERVER['PHP_SELF']?>" method="post"> <label></label> <select name="model"> <option value="default" selected="selected">Please Select Machine</option> <option value="HB-P830">HB-P830</option> <option value="HB-830">HB-830</option> <option value="HB1030S1">HB-1030 Series 1</option> <option value="HB1030S2">HB-1030 Series 2</option> <option value="HB1430S1">HB-1430 Series 1</option> <option value="HB1430S2">HB-1430 Series 2</option> <option value=""></option> <option value="HB-P830CE">HB-P830CE</option> <option value="HB-830CE">HB-830CE</option> <option value="HB1030CES1">HB-1030CE Series 1</option> <option value="HB1030CES2">HB-1030CE Series 2</option> <option value="HB1430CES1">HB-1430CE Series 1</option> <option value="HB1430CES2">HB-1430CE Series 2</option> </select> <label></label> <select name="location" onChange="getfunit()"> <option value="default" selected="selected">Please Select Part Location</option> <option value="Base">Base</option> <option value="Decals">Decals</option> <option value="Lower Control">Lower Control</option> <option value="Misc">Misc</option> <option value="Railing">Railings</option> <option value="Scissors">Scissors</option> <option value="Upper Control">Upper Control</option> </select> <label></label> <div id="funitdiv"><select name="funit"> <option>Please Select Functional Circuit</option> </select></div> <label></label> <input type="submit" name="submit" value="Submit" id="submit"> </form> php processing code <? $modelId=$_POST['model']; $locationId=$_POST['location']; $link = mysql_connect('localhost', 'custkis6_dealers', 'locate'); //changet the configuration in required if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('custkis6_parts'); $query="SELECT fcircuit FROM hybrid WHERE model='$modelId' AND plocation='$locationId'"; $result=mysql_query($query); ?> <select name="funit"> <option>Select Functional Circuit</option> <option><? echo $modelId ?></option> <option><? echo $locationId ?></option> <? while($row=mysql_fetch_array($result)) { ?> <option value><?=$row['fcircuit']?></option> <? } ?> </select> This is a sample request and im getting undefined under model yet but the location is coming out right. Request URL:http://hybridlifts.com/position/pages/ss/getfunit.php?model=undefined&location=Base Request Method:POST Status Code:200 OK Quote Link to comment https://forums.phpfreaks.com/topic/251137-passing-multiple-values-with-ajax/#findComment-1288330 Share on other sites More sharing options...
requinix Posted November 15, 2011 Share Posted November 15, 2011 var strURL="getfunit.php?model="+document.fparts.model.vaule+"&location="+document.fparts.location.value; Look carefully. Quote Link to comment https://forums.phpfreaks.com/topic/251137-passing-multiple-values-with-ajax/#findComment-1288422 Share on other sites More sharing options...
justinjkiss Posted November 15, 2011 Author Share Posted November 15, 2011 wow i just stared at that for a few minutes... cant believe i had a typo there... problem 1 solved now the php isnt reading the values right... ugg time to look for typos again.. Quote Link to comment https://forums.phpfreaks.com/topic/251137-passing-multiple-values-with-ajax/#findComment-1288426 Share on other sites More sharing options...
justinjkiss Posted November 15, 2011 Author Share Posted November 15, 2011 POST changed to get and i got my values. YAY... now to strip the results so i dont have excessive repeating. Think i can pull this one off unless anybody has a quick fix there too. http://hybridlifts.com/position/pages/ss/parts2.php I got some tweaking to do now... seems the functional unit get populated but when i run my php post action im not passing a value .... i think i might have it though THANKS SO much for pointing out my typo!!!! Quote Link to comment https://forums.phpfreaks.com/topic/251137-passing-multiple-values-with-ajax/#findComment-1288430 Share on other sites More sharing options...
justinjkiss Posted November 15, 2011 Author Share Posted November 15, 2011 UPDATE: The AJAX works yay... i suppose i should change this topic to solved because the AJAX is solved. I still got the issue of deduplicating the php results. Any assistance here or should i make a php forum post. Quote Link to comment https://forums.phpfreaks.com/topic/251137-passing-multiple-values-with-ajax/#findComment-1288460 Share on other sites More sharing options...
justinjkiss Posted November 15, 2011 Author Share Posted November 15, 2011 AND figured it out (select distinct) thanks for you help!!!! Quote Link to comment https://forums.phpfreaks.com/topic/251137-passing-multiple-values-with-ajax/#findComment-1288466 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.