javascript - How to Display Column Data in Input Once Different Column Data Has Been Selected? -


i have form select field , input field:

enter image description here

the select field takes of customer names customer table's customer_name column, , allows user choose customer name. once customer's name has been chosen, take name , display in "add customer name" input, , take customers phone number (from phone_num column in customer table) , display in "customer phone" input.

i using my_sql , php this.

so far, can correctly display customer names in "customer" select field. but, name not appear in "add customer name" input nor display customer's phone number in "customer phone" input.

does know how using php, javascript, or perhaps mix of both?

here code part of web form:

<script type="text/javascript">     $(document).ready(function () {         $("#customer").change(function() {             if($( "#customer option:selected" ).text() == 'add customer') {                     $( "#customer_name" ).show();                     $( "#cusphone" ).show();                     $( "#cusphone1" ).show();                     $( "#customer_name1" ).show();             } else {                 $( "#customer_name" ).hide();                 $( "#cusphone" ).hide();                 $( "#cusphone1" ).hide();                 $( "#customer_name1" ).hide();             }         }); });  </script>  <form id="form1" name="form1" method="post" action="add_invoice.php" enctype="multipart/form-data" class="form-horizontal" role="form">            <div class="form-group">             <label for="travel_task" class="col-sm-4 control-label">customer<span class="brand-color"></span>:</label>             <div class="col-sm-8">               <select id="customer" name="customer" required class="chosen-select-deselect form-control" width="380">               <option value=''></option>                   <?php                     $result = mysqli_query($dbc, "select distinct(customer_name) customer");                     while($row = mysqli_fetch_assoc($result)) {                         if ($customer_name == $row['customer_name']) {                             $selected = 'selected="selected"';                         } else {                             $selected = '';                         }                          echo "<option ".$selected." value = '".$row['customer_name']."'>".$row['customer_name']."</option>";                             }                   ?>                   <option value = 'other'>add customer</option>               </select>             </div>           </div>              <div class="form-group">             <label for="travel_task" id="customer_name" style="display: none;" class="col-sm-4 control-label">add customer name:</label>             <div class="col-sm-8">                 <input name="customer_name" id="customer_name1" type="text" class="form-control" style="display: none;"/>             </div>           </div>            <div class="form-group">             <label for="site_name" id="cusphone1" style="display: none;" class="col-sm-4 control-label">customer phone:</label>             <div class="col-sm-8">                 <input name="cusphone" id="cusphone" type="text" class="form-control" style="display: none;"/>             </div>           </div> 

thank help. appreciated.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -