简体   繁体   English

使用从表中获取值的函数填充列表框

[英]Populating listbox with a function that gets values from a table

I have 2 listboxes on my web page. 我的网页上有2个列表框。 I want to populate second listbox by a value selected in first list box. 我想通过在第一个列表框中选择的值填充第二个列表框。 When I select an option in firstlistbox it queries a table on my backend and populates the secondlist box based on the results. 当我在firstlistbox中选择一个选项时,它会查询后端的一个表并根据结果填充secondlist框。 I cannot use php script inside a javasript so what should I do? 我不能在javasript内使用php脚本,那该怎么办?

You are asking how create a sub categories list box. 您在问如何创建子类别列表框。 You need create it easily using AJAX. 您需要使用AJAX轻松创建它。

Here are the steps you need to do. 这是您需要执行的步骤。

  1. Populate first list box and call function loadData() when you change item. 更改项目时,填充第一个列表框并调用函数loadData()。
  2. send ajax request to getdata.php with selected category_Id parameter 使用选定的category_Id参数将ajax请求发送到getdata.php
  3. Make getdata.php to output second list box according to category_Id 使getdata.php根据category_Id输出第二个列表框
  4. Display ajax response on page as html 在页面上将ajax响应显示为html

I found this article for you. 我为您找到了这篇文章。

Hope it helps. 希望能帮助到你。

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

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