inamul70 Posted December 9, 2011 Share Posted December 9, 2011 I am having two tables. Order and grademaster.. In grademaster table i have two fields 'packing' and 'condition'.. I am using php mysql and ajax. If a person select grade value of packing and condition should be autopopulate in the textboxes.. I have successfully loaded value of one textbox through php ajax but the second text box cannot accept values. I have tried calling two functions from onchange() but no result.. Please suggest me how can i populate two text boxes from one ajax selection. my code below //javascript <script type="text/javascript"> function showUser(str) { if (str=="") { document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getgradepacking.php?q="+str,true); xmlhttp.send(); } </script> <div> <label>Packing <strong>*</strong></label> <textarea id="txtHint" name="txtpacking" id="txtpacking" cols="42" rows="4"></textarea> </div> //getgradepacking.php <?php $q=$_GET["q"]; include('includes/connect.php'); mysql_select_db($Db, $link); $sql="SELECT * FROM grademaster WHERE gradeid = '".$q."'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $packing = $row['packing']; echo $packing; ?> Quote Link to comment Share on other sites More sharing options...
sunfighter Posted December 9, 2011 Share Posted December 9, 2011 In your php file you have to combine the two columns into a single echo. We're going to do this with a implode command. I'm using '/' to separate the two pieces of information. You can use anything you want as long as it is not used in either of the two resources. PHP: ... $row = mysql_fetch_array($result); $combo = implode('/', $row); echo $combo; In the javascript section we have to separate them. Where we once had: document.getElementById("txtHint").innerHTML=xmlhttp.responseText; We put: pieces = xmlhttp.responseText; number1 = pieces.search('/'); first = pieces.substr(0,number1); second = pieces.substring(number1+1); document.getElementById("txtHint").innerHTML= first; document.getElementById("nextDiv").innerHTML= second; Quote Link to comment Share on other sites More sharing options...
inamul70 Posted December 13, 2011 Author Share Posted December 13, 2011 Thanks ... for help.. its solved. 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.