简体   繁体   English

我想做一个条件,如果我从第一个下拉列表中选择这个项目,它会只显示我在第二个下拉列表中选择的项目

[英]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.

相关问题 在第一个下拉菜单被选中后显示第二个下拉菜单的内容。 - Show content of 2nd Drop down after 1st Drop down getting selected. 如何根据第一个下拉值使第二个下拉列表自动选择值 - How to make 2nd drop down list auto select value based on 1st drop down value Angular JS-1链接到2st链接到3rd。 现在,我需要从第3个下拉列表中选择数据,以便在另一个文本区域中显示 - Angular JS- 1st Dropdown linked to 2nd linked to 3rd. Now I need selected data from 3rd drop down to display in another textarea 与第二下拉选择相关的第二下拉选择 - 2nd Drop Down selection to be related to the selection on the 1st Drop Down Selection 通过在codeigniter php中使用ajax,根据第一个下拉结果填充第二个下拉列表 - populate 2nd drop down based on 1st drop down result by using ajax in codeigniter php 如何根据第一个下拉列表过滤第二个下拉列表 - how to filter 2nd drop-down list according to 1st drop-down list 我在 select 之后的年份下降了我想在循环中仅显示选定年份的画廊 - I have year drop down after year select I want to show gallery in loop only selected year 下拉菜单:如何取消激活第一个(选定)选项? - drop down menu: how to make deactivate the 1st (selected) option? 如何在第一个选择上禁用(或更改颜色)第二个下拉选项? - How to disable (or change color) of 2nd drop down option depenging on 1st selection? 一旦我在第一个下拉列表中选择了不同的选项,如何重置第三个动态下拉列表? - How do I make my 3rd dynamic drop down reset once I pick a different option in the 1st drop down?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM