jquery - Javascript - Change suggested text before placing it in the textbox -
i have html textbox uses javascript autocomplete feature in jquery ui - v1.11.4. suggested string textbox concatenation of several columns (patient_no,patient_name,age , residence) table in database. wanted truncate part of string since require patient_no column placed in textbox.
possible text suggestion : '00032 >> tom michael >> 14yrs >> westlands'
what want placed in textbox : '00032'
below code
//html <input name="patientno" id="patientno" type="text" /> //autocomplete.php $pat_no_seq_result = pg_query("select patient_no || ' >> ' || surname || ' ' || other_name || ' >> ' || (current_date-year_of_birth)/365 || 'yrs' || ' >> '||residence hp_outpatient_register;"); $dname_list = array(); while ($row = pg_fetch_row($pat_no_seq_result)) { $dname_list[] = $row[0] ; } //javascript <script type="text/javascript"> $(function() { var availabletags = <?php include('autocomplete.php'); ?>; $("#patientno").autocomplete({ source: availabletags,//autofocus: true select: function(event, ui) { getpatientno(ui.item.value); } }); function getpatientno(value) { var patno = value.substring(0, value.indexof(' ')); document.getelementbyid("patientno").value = patno; } }); </script>
is there way can truncate string selected user before placing in text field. if there better way i'm using, please advise.
Comments
Post a Comment