简体   繁体   English

如何基于另一个下拉选择动态填充的下拉列表中选择?

[英]How to dynamically populate options on dropdown lists based on selection in another dropdown?

I have a table which has the information of a category, say a product. 我有一张桌子,上面有类别信息,例如产品。 I have listed them in a dropdown menu. 我已经在下拉菜单中列出了它们。 Now, what I need to do is, list the sub category of the selected category in a next dropdown menu. 现在,我需要做的是,在下一个下拉菜单中列出所选类别的子类别。 I hope, javascript is required, but I am not that familiar with javascript yet. 我希望javascript是必需的,但我对javascript还不熟悉。

Would be much thankful for the help. 非常感谢您的帮助。

You should use AJAX. 您应该使用AJAX。

With jQuery it is very simple: 使用jQuery,它非常简单:

$('#select1').change(function(){
$.ajax({
   //Send to php script category id. This script returns all subcategories
   $.ajax({
      type: "POST",
      url: location.href,
      data: data,
      success : function (data)
      {   
         // Your return categories in data
         // Append list options to select2
      } 
});
});

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

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