Lanka Developers Community

    Lanka Developers

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Shop

    How to change two input fields with one onchange event

    Back-End Development
    php ajax html5 javascript
    2
    2
    500
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • akashmanujaya
      akashmanujaya last edited by

      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

      1 Reply Last reply Reply Quote 0
      • tnlthanzeel
        tnlthanzeel Web Development last edited by

        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>

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post

        1
        Online

        3.7k
        Users

        1.3k
        Topics

        5.3k
        Posts

        • Privacy
        • Terms & Conditions
        • Donate

        © Copyrights and All right reserved Lanka Developers Community

        Powered by Axis Technologies (PVT) Ltd

        Made with in Sri Lanka

        | |