Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should do something like this with <a href="http://jquery.com/" rel="nofollow noreferrer">jQuery</a> + <a href="http://www.json.org/" rel="nofollow noreferrer">JSON</a></p> <p>First of all download jquery from <a href="http://code.jquery.com/jquery-1.4.2.min.js" rel="nofollow noreferrer">here</a> and include it in your application. </p> <p>If <strong>home.php</strong>, your downloaded jquery file(<strong>jquery-1.4.2.min.js</strong>) and <strong>getData.php</strong> are in the same folder then your <strong>home.php</strong> will be look like this:</p> <p><strong>home.php</strong> (file that contain your form)</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="jquery-1.4.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function(){ jQuery('#Client_ID').live('change', function(event) { $.ajax({ url : 'getData.php', type : 'POST', dataType: 'json', data : $('#myform').serialize(), success: function( data ) { for(var id in data) { $(id).val( data[id] ); } } }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id='myform'&gt; &lt;select name='Client_ID' id='Client_ID'&gt; &lt;option value=''&gt;Select&lt;/option&gt; &lt;option value='1'&gt;Client 1&lt;/option&gt; &lt;option value='2'&gt;Client 2&lt;/option&gt; &lt;/select&gt; &lt;input type='text' name='address1' id='address1'&gt; &lt;input type='text' name='address2' id='address2'&gt; &lt;select name='gender' id='gender'&gt; &lt;option value=''&gt;Select&lt;/option&gt; &lt;option value='1'&gt;Male&lt;/option&gt; &lt;option value='2'&gt;Female&lt;/option&gt; &lt;/select&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>getData.php</strong></p> <pre><code>&lt;?php $clientId = $_POST['Client_ID']; // Selected Client Id $query = "SELECT Address1, Address2 from Client where Client_ID = $clientId"; $result = mysql_query($query); $row = mysql_fetch_array($result, MYSQL_ASSOC) $add1 = $row[Address1]; $add2 = $row[Address2]; $gender = 1; $arr = array( 'input#address1' =&gt; $add1, 'input#address2' =&gt; $add2, 'select#gender' =&gt; $gender ); echo json_encode( $arr ); ?&gt; </code></pre> <p>I have tested this code on my machine and it is working.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload