How do i populate input field when i have multiple AJAX calls?
i have a drop down field dependant on the first drop down. I want to populate input fields with other row data from database dependant on the second selection.
The fist call works fine and populates a dependant dropdown after the first selection.
the second appears to be returning correct values but does not populate the input field.
I am very new to PHP.
I hope you can help
e.g.
$(document).ready(function(){
$("#selectWard").change(function(){
var wardId = $(this).val();
$.ajax({
url:"ajaxpro.php",
method:"POST",
data:{'WardID':wardId},
success:function(data){
$("#patname").html(data);
}
});
});
$("#patname").change(function(){
var patId = $(this).val();
$.ajax({
url:"ajaxURN.php",
method:"POST",
data:{'PatID':patId},
success:function(data){
$("#URN").html(data);
}
});
});
});
PHP here (ajaxURN.php)
<?php
require('dbconfig.php');
$sql = "SELECT * FROM currentpatients WHERE ID ='".$_POST['PatID']. "'";
$result =mysqli_query($con,$sql);
while ($row=mysqli_fetch_array($result)){
$output = '<input value ="'.$row["URN"].'">';
}
echo $output;
?>
input field mark up here: (index.php)
<div class = "row">
<label for="createURN">URN</label>
<input id = "URN" type="text" name="createURN" value = "">
</div>