选择第一个下拉列表时获取下拉列表的值
<select style="width:300px;" id="n" name="userListingCategory">
<option disabled="disabled">Category...</option>
<?php while($row = $sth2->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['catID'] . ">" .$row['catName']."</option>";}
unset($sth2);
?>
</select>
<select style="width:340px;" id="n" name="userListingSCategory">
<option disabled="disabled">Sub-Category...</option>
<?php while($row = $sth3->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['scatID'] . ">" .$row['scatName']."</option>";}
unset($sth3);
?>
这会生成两个带有值的下拉列表。
单击 userListingCategory
后,我希望运行以下 SQL 来获取关联的子类别 (userListingSCategory
):
SELECT scatID, scatName
FROM Category C, SubCategory SC
WHERE $valueOfFirstSelected = SC.catID;
本质上,这将获取与 ID 关联的子类别 ID 和名称最初选择的类别的名称(因此:$valueOfFirstSelected
)
有人吗? Ajax 或 jQuery 或 Php 将是最有益的。
谢谢
<select style="width:300px;" id="n" name="userListingCategory">
<option disabled="disabled">Category...</option>
<?php while($row = $sth2->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['catID'] . ">" .$row['catName']."</option>";}
unset($sth2);
?>
</select>
<select style="width:340px;" id="n" name="userListingSCategory">
<option disabled="disabled">Sub-Category...</option>
<?php while($row = $sth3->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['scatID'] . ">" .$row['scatName']."</option>";}
unset($sth3);
?>
This makes two dropdown lists with values.
Upon clicking a userListingCategory
, I want the following SQL to run to get the associated subcategories (userListingSCategory
):
SELECT scatID, scatName
FROM Category C, SubCategory SC
WHERE $valueOfFirstSelected = SC.catID;
Which will in essence, get the SubCategory ID and Name associated with the ID of the Category originally selected (hence: $valueOfFirstSelected
)
Anyone? Ajax or jQuery or Php would be most beneficial.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的文件:
ajax_fill_select_two.php:
最好的解决方案是通过ajax响应发送
JSON
数据并添加option
字段通过 JavaScript 选择两个your file:
ajax_fill_select_two.php:
the best solution is send
JSON
data thru ajax response and addoption
fields to select_two via javascript