<select name="docname" class="form-control" id="docname" required>
<option Value="">Please Choose Doctor</option>
<?php
foreach($data as $crow){
echo "<option value='$crow->name'>$crow->name</option>";
}
?>
</select>
<input type="date" name="bdate" class="form-control txtDate" id="txtHint" required>
<div class="form-group" id="txtHint1"></div>
<script>
$(document).ready(function(){
$('#docname').on('change',function(){
var doc_id=this.value;
$.ajax({
url:"subcat.php",
type:"POST",
data:{
doc_id:doc_id
},
cache:false,
success:function(result){
$("#txtHint").html(result);
$('#txtHint1').html('<optionvalue="">SelectDateFirst</option>');
}
});
});
$('#txtHint').on('change',function(){
var date_id=this.value;
$.ajax({
url:"catsubcat.php",
type:"POST",
data:{
date_id:date_id
},
cache:false,
success:function(result){
$("#txtHint1").html(result);
}
});
});
});
</script>
Here you can see Ajax and Other Code. How I Fetch First Ajax value with 3rd Id.
For e.g First I select Doctor Name then I select an appointment date and Last I want to fetch the Time slot of That doctor for this date.
Can anyone suggest to me how could I do that??
5
Answers
Pass data like this :
data:{
‘doc_id’: doc_id,
‘blob_data_username’: blob_username,
‘blob_data_password’: blob_password
},
To get doctor name or selected option use
$('#docname').val()
As I do not use jQuery I cannot offer advice/help on that but with some fairly simple vanilla Javascript you can quite easily use AJAX to fetch data and use the response to help construct the next element in your form ( which is how I interpret your needs
"First I select Doctor Name then I select an appointment date and Last I want to fetch the Time slot of That doctor for this date."
)The following code sends All ajax requests to the same page ( this could be a totally separate script if needed ) with the value from whichever form element the user used to make the current selection.
The event handler inspects the element that invokes it to see if there is a following HTML element, defined with a dataset attribute
data-next
. Using that dataset attribute in the ajax callback you can populate the following element with the data returned from the db lookup ( ajax request response )The ajax request sends two pieces of information in each request – the name/value of the selected element and the dataset value of the next element. With these you can easily setup logic in PHP that runs the appropriate SQL query and returns the correct response. In the code here this is emulated with simple data responses ( date / time ) – the response could be considerably more complex (json for instance) but then the ajax callback would need to be modified accordingly.
Hope it makes sense. Copy to a new PHP file and run it perhaps
You have two options.
data: $("#frmRegistroDatos").serialize(),
data: {name:name, id:id, phone:phone},
I hope this help you.
you can pass multiple parameters by using these ways
1.
2.