简体   繁体   English

可靠的下拉菜单

[英]Dependable Drop Down Menus

After creating three dependable drop down menus using jquery,ajax and php. 使用jquery,ajax和php创建三个可靠的下拉菜单后。 After my dropdown menus have already been populated, for example when i select a value in the first drop down menu, the second drop down menu is created based on the first selected value and so on with the third drop down menu when i select a value in the second drop down menu. 在我的下拉菜单已经填充之后,例如当我在第一个下拉菜单中选择一个值时,第二个下拉菜单是根据第一个选定的值创建的,依此类推,第三个下拉菜单是在我选择一个值时创建的在第二个下拉菜单中。 Now how to capture the selected values again altogether to perform further queries on the database. 现在,如何再次完全捕获选定的值以对数据库执行进一步的查询。

Set the same class name for all select box and every change in select box run the function and run each function which all selected to get all the selected values like this 为所有选择框设置相同的类名,并且选择框中的每个更改都将运行该函数并运行所有被选中的每个函数以获取所有选中的值,如下所示

 dropdown1 =''; dropdown2 =''; dropdown3 =''; $('.qm_SELECT_sel').change(function(){ // $all_drop_down_values =[]; $('.qm_SELECT_sel option:selected').each(function(){ if($(this).val()!='' && $(this).attr('name')=='dropdown1') { dropdown1 =$(this).val(); } if($(this).val()!='' && $(this).attr('name')=='dropdown2') { dropdown2 =$(this).val(); } if($(this).val()!='' && $(this).attr('name')=='dropdown3') { dropdown3 =$(this).val(); } }); if(dropdown1!='' && dropdown3 !='' && dropdown3 !='') { $.ajax({ url: 'your_destination_page.php', type:'POST', data:{dropdown1:dropdown1,dropdown2:dropdown2,dropdown3:dropdown3}, success:function(data) { alert("hi"); } }); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="dropdown1" class="qm_SELECT_sel"> <option value="" >select 1 </option> <option value="1" >1 </option> <option value="2" >2</option> </select> <select name="dropdown2" class="qm_SELECT_sel" > <option value="" >select 2 </option> <option value="1" >1 </option> <option value="2" >2</option> </select> <select name="dropdown3" class="qm_SELECT_sel" > <option value="" >select 2 </option> <option value="1" >1 </option> <option value="2" >2</option> </select> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM