I want solution for reading a value from dropdown list and send it to the same page usng GET method. I think ajax and jquery will fulfill this.
if i select 'Inpatient' from dropdown list then it automatically available on same page.
<div id="div_for_patienttype">
Choose patient type:<select id="select_patient_id"name="patient_type">
<option >Select patient type</option>
<option value="InPatient">InPatient</option>
<option value="OutPatient">OutPatient</option>
</select>
</div>
I coded this and working fine but one problem is when I selects patient type the page gets refreshed and value in dropdown is 'Select patient type'.I actually wants value of dropdown remains same i.e selected.
code:
$(document).ready(function(){
$("#select_patient_id").change(function(){
var selected_patient=$(this).val();
sendType(selected_patient);
});
});
function sendType(type)
{
$.ajax({
type:"GET",
url:"dispres.php",
data:({patientType:type}),
success:function(success)
{
window.location.href="dispres.php?patientType="+type;
}
});
}
And how can I optimize this jquery and ajax code?