[英]I want to make a condition in which if I select this item from 1st drop down show it shows me only selected items in 2nd drop down
If I want to select a doctor's name from my form drop-down so it only shows his/her specialty on the second drop-down below that.如果我想从我的表单下拉列表中选择医生的名字,那么它只会在下面的第二个下拉列表中显示他/她的专业。 For example, Dr. Sarah is Gynaecologist so when I select her name from the drop-down menu so it only shows her specialty down in the second drop-down and hides another specialty.例如,莎拉博士是妇科医生,所以当我从下拉菜单中选择她的名字时,它只会在第二个下拉菜单中显示她的专业,并隐藏另一个专业。
And for example, if I select Dr. James and he is Gynaecologist & a Family Planner consultant, the Drop-down menu below should show Gynae & Family Planning clinic service and nothing else.例如,如果我选择 James 医生并且他是妇科医生和计划生育顾问,下面的下拉菜单应显示妇科和计划生育诊所服务,而没有其他内容。
So the user can select any one of the services if any "Doctor" has more than 1 specialty.因此,如果任何“医生”具有 1 个以上的专业,则用户可以选择任何一项服务。 Or if the user selects any service like Gynae so the drop-down menu only shows Gynae consultants in the list, For example, if I select "Gynaecology" from the service section so the upper drop-down only shows me those doctors names which are Gynae consultant or if I select Service "Family Clinic" so it shows me only those doctors name which is Gynae consultant.或者,如果用户选择了 Gynae 之类的任何服务,则下拉菜单仅显示列表中的 Gynae 顾问,例如,如果我从服务部分选择“妇科”,则上部下拉菜单仅显示那些医生姓名Gynae 顾问,或者如果我选择服务“家庭诊所”,那么它只会向我显示那些是 Gynae 顾问的医生的名字。 If Dr. James are Gynae and Family planner consultant so if the user selects gynae so it shows Dr. James name also with Dr. Sarah如果 James 博士是 Gynae 和家庭计划顾问,那么如果用户选择了 gynae,那么它也会显示 James 博士的名字和 Sarah 博士
<select name="doctorsname" id="doctors" class="form-control" required>
<option value="No Doctor Selected">Select Your Doctor</option>
<option value="Dr. Sarah (Gynaecologist)> Dr.Sarah (Gynaecologist) </option>
<option value="Dr. James (Gynaecologist & Family Planner Consultant)">Dr. James (Gynaecologist & Family Planner Consultant)</option>
</select>
<select name="services" id="service" class="form-control" required>
<option value="No Service Selected">Select Your Services</option>
<option value="Gynaecology">Gynaecology</option>
<option value="Family Planing Clinic">Family Planing Clinic</option>
</select>
I don't know if this is exactly what you were looking for but you can go on this basis我不知道这是否正是您要寻找的,但您可以在此基础上继续
$('#doctors').on('change',function(){ let doctorsService = $(this).find(':selected')[0].dataset.service; if( doctorsService != "none"){ $('#service').find('option').each(function(){ if( $(this)[0].dataset.service != "none"){ if( doctorsService.split(',').includes( $(this)[0].dataset.service)) $(this).show(); else $(this).hide(); } }); }else{ $('#service').find('option').show(); } }); $('#service').on('change',function(){ let service = $(this).find(':selected')[0].dataset.service; if( service != "none"){ $('#doctors').find('option').each(function(){ if( $(this)[0].dataset.service != "none"){ if( $(this)[0].dataset.service.indexOf(service) != -1) $(this).show(); else $(this).hide(); } }); }else{ $('#doctors').find('option').show(); } });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select name="doctorsname" id="doctors" class="form-control" required> <option value="No Doctor Selected" data-service="none">Select Your Doctor</option> <option value="Dr. Sarah (Gynaecologist)" data-service="1">Dr.Sarah (Gynaecologist)</option> <option value="Dr. James (Gynaecologist & Family Planner Consultant)" data-service="1,2">Dr. James (Gynaecologist & Family Planner Consultant)</option> </select> <select name="services" id="service" class="form-control" required> <option value="No Service Selected" data-service="none">Select Your Services</option> <option value="Gynaecology" data-service="1">Gynaecology</option> <option value="Family Planing Clinic" data-service="2">Family Planing Clinic</option> </select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.