php - autofill text box from database value based on 1st textbox value -


i trying autofill values textbox database based on value entered in text box. should dob enter name.

i tried following example http://www.htmlblog.us/open-source/jqueryautocompleterelatedfields.html dont know why not working me.

here code

html

<form name="appointment" method="post" action="apponiment_submit.php" enctype="multipart/form-data" onsubmit="return validate()"> <table class="selection">  <tr><td colspan="3"><center><font color="red"><strong>fields marked star compulsory</strong></font></center></td></tr> <tr><td>patient name  :</td><td><input type="text" name="p_name" id="p_name" /><strong><font color="red">*</font></strong></td></tr>  <tr><td>dob :</td><td><input type="text" name="p_dob" id="p_dob" class="tcal" /></td></tr> </table> </form> 

script

<script type="text/javascript">          jquery(document).ready(function(){              $('.p_name').autocomplete({                 source:'fill_patient_info1.php',                  minlength:2,                 select:function(evt, ui)                 {                     // when zipcode selected, populate related fields in form                     this.form.p_name.value = ui.item.p_name;                     this.form.p_dob.value = ui.item.p_dob;                 }             });         });      </script> 

and in fill_patient_info1.php

// if 'term' variable not sent request, exit if ( !isset($_request['term']) )      exit;  echo $_request['term']; // connect database  $dblink = mysql_connect('localhost', 'root', '') or die( mysql_error() ); mysql_select_db('hospital');   $rs = mysql_query('select patient_name,dob patient patient_name "'. mysql_real_escape_string($_request['term']) .'%" order patient_name asc limit 0,10', $dblink);  $data = array(); if ( $rs && mysql_num_rows($rs) ) {     while( $row = mysql_fetch_array($rs, mysql_assoc) )     {         $data[] = array(             'label' => $row['patient_name'] .', '. $row['dob'] .' '. $row['patient_name']          );     } }  // jquery wants json data echo json_encode($data); flush(); 

i not versed json , jquery. not getting doing wrong. instead of $_request['term']; tried putting $_request['p_name']; , did not work.

please suggest

in file fill_patient_info1.php not have request term or p_name. have write down full query, without condition. jquery ui auto complete rest. sql should be:

select patient_name, dob patient order patient_name limit 10 

update: when create array, if want populate dub too, need specifiy value this:

$data[] = array(         'label' => $row['patient_name'] .', '. $row['dob'] .' '. $row['patient_name'] ,         'value' => $row['dob']     ); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -