i will love to have the solution to this challenge below. i want a situation when i select the Doctor option it hides the list of specialist and when i select the specialist it shows the list of specialist. thanks
<tr><td colspan=2 ><strong>Doctor Locator</strong></td></tr>
<tr><td>
<?php
$doc = 'Doctors';
$spel = 'Specialist';
$medic = array($doc, $spel);
sort ($medic);
echo "<select>";
foreach ($medic as $m)
{
echo "<option value=\"$m\">$m</option>";
}
echo "</select> <br/> ";
?>
<select name="txt_specialize" style="width: 400px; height: 25px">
<?php
$specialist = array('Surgeon','Neurosurgeon','','Neurologist','Occupational Medicine Physician','Ophthalmologist',
'Oral and Maxillofacial Surgeon','Pathologist','Psychiatrist','Podiatrist','Nephrologist','Otolaryngologist',
'Internal Medicine Physician','Gastroenterologist','Emergency Physicians','Hermatologist','Dermatologist',
'Anesthesiologist','Immunologist','Orthopaedic Surgeon','Radiation Onconlogist','Gynaecologist','Dentist',
'Optician','Cardiologist','Pediatrician','Urologist','Diagnostic Radiologist','Pulmonary Medicine Physician',
'Rheumatologist','Plastic Surgeon');
sort ($specialist);
foreach ($specialist as $s)
{
echo "<option value=\"$s\">$s</option>";
}
echo "</select>"
?>
</td></tr>
<tr><td>
You can easily do this with jQuery. If you give the first select an id of "type", you can add the following jQuery:
$(document).ready(function(){
$("select[name='txt_specialize']").hide();
$("select#type").change(function(){
if($(this).val() == 'Doctor')
{
$("select[name='txt_specialize']").hide();
}
else
$("select[name='txt_specialize']").show();
});
});
Attach a change
event to your first select box.
In the callback, update the selectbox content for your taste.
Add data-attributes to txt_specialize $s and done write script like this: select doctor
$('#doctor').change(function(e){
var doc = $('#doctor').val();
$("#specialist option").each(
function(){
if ($(this).attr('data-doctor')==doc){
$(this).show()
}else{
$(this).hide()
}
})
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.