How to change two input fields with one onchange event



  • i want to change two inputs according to the selected value form another field
    i have try this code and it gives two value that i want but it not showing on two different filed. its only showing two values in one field as two selections
    This is my code

    book-appointment .php

    <script>
    function getdoctor(val) {
    	$.ajax({
    	type: "POST",
    	url: "../get_doctor.php",
    	data:'specilizationid='+val,
    	success: function(data){
    		$("#doctor").html(data);
    	}
    	});
    }
    </script>	
    
    <script>
    function getAppNumber(val) {
    	$.ajax({
    	type: "POST",
    	url: "../get_doctor.php",
    	data:'doctor='+val,
    	success: function(data){
    		$("#AppNumber").html(data);
    	}
    	});
    }
    </script>	
    
    
    <script>
    function getfee(val) {
    	$.ajax({
    	type: "POST",
    	url: "../get_doctor.php",
    	data:'doctor='+val,
    	success: function(data){
    		$("#fees").html(data);
    	}
    	});
    }
    </script>
    
    <div class="form-group">
    	<label for="DoctorSpecialization">
    		Doctor Specialization
    	</label>
    	<select name="Doctorspecialization" class="form-control" onChange="getdoctor(this.value);" required="required">
    		<option value="">Select Specialization</option>
    		<?php 
    			$ret=mysqli_query($con,"select * from doctorspecilization");
    		        while($row=mysqli_fetch_array($ret))
    			{
    			?>
    		<option value="<?php echo htmlentities($row['specilization']);?>">
    		<?php echo htmlentities($row['specilization']);?>
    		</option>
    		<?php } ?>
    							
    	</select>
    </div>
    
    
    
    <div class="form-group">
            <label for="doctor">
    	     Doctor
    	</label>
    	<select name="doctor" class="form-control" id="doctor" onChange="getfee(this.value);getAppnumber(this.value);" required="required">
    	       <option value="">Select Doctor</option>
    	</select>
    </div>
    	<div class="form-group">
    		<label for="consultancyfees">
    		         Consultancy Fees
    		</label>
    	<select name="fees" class="form-control" id="fees"  readonly>
    
    	</select>
    </div>
    <div class="form-group">
    	<label for="appinmentnumber">
    		Appoinment Number
    	</label>
    	<select name="AppNumber" class="form-control" id="AppNumber"  readonly>
    	</select>
    </div>
    

    get_doctor.php

    <?php
    include('include/config.php');
    if(!empty($_POST["specilizationid"])) 
    {
    
     $sql=mysqli_query($con,"select doctorName,id from doctors where specilization='".$_POST['specilizationid']."'");?>
     <option selected="selected">Select Doctor </option>
     <?php
     while($row=mysqli_fetch_array($sql))
     	{?>
      <option value="<?php echo htmlentities($row['id']); ?>"><?php echo htmlentities($row['doctorName']); ?></option>
      <?php
    }
    }
    
    
    if(!empty($_POST["doctor"])) 
    {
    
     $sql=mysqli_query($con,"select docFees from doctors where id='".$_POST['doctor']."'");
     while($row=mysqli_fetch_array($sql))
     	{?>
     <option value="<?php echo htmlentities($row['docFees']); ?>"><?php echo htmlentities($row['docFees']); ?></option>
      <?php
    }
    }
    
    if(!empty($_POST["doctor"])) 
    {
    
     $sql=mysqli_query($con,"select doctorId,COUNT(AppNumber)+1 as nextAppNumber from appointment  where doctorId='".$_POST['doctor']."' group by doctorId order by doctorId DESC");
     while($row=mysqli_fetch_array($sql))
     	{?>
     <option value="<?php echo htmlentities($row['nextAppNumber']); ?>"><?php echo htmlentities($row['nextAppNumber']); ?></option>
      <?php
    }
    }
    
    ?>
    
    
    

    Thank you for help



  • you can write all your javascripts in on tag.

    <script>
    function getdoctor(val) {
    $.ajax({
    type: "POST",
    url: "../get_doctor.php",
    data:'specilizationid='+val,
    success: function(data){
    // i assume that your data on ajaxs success has 2 properties in the object
    $("#input1").val(data.item1);
    $("#input2").val(data.item1);
    }
    });
    }
    </script>