gpt4 book ai didi

javascript - 如何通过表单提交传递下拉列表的值?

转载 作者:行者123 更新时间:2023-12-03 06:41:56 25 4
gpt4 key购买 nike

我有这两个下拉菜单: enter image description here

我必须根据“选择类别”下拉列表中选择的值提供“选择项目”下拉列表的值。

这是我的 PHP 选择类别下拉菜单:

<form>
...
<select name="category" id="category" value="category" class="form-control ddplaceholder" style="width:220px;font-size:18px;font-family:Roboto;" onclick="document.form.submit();">
<option value="" disabled selected>Select Category</option>
...
<input type="submit" name="submit" style="width:20%;padding:15px;" value="Update"</input>
...</form>

但是什么也没发生。我该怎么做?

最佳答案

尝试使用 onchange 而不是 onclick

<form>
...
<select name="category" id="category" value="category" class="form-control ddplaceholder" style="width:220px;font-size:18px;font-family:Roboto;" onchange="document.forms[0].submit();">
<option value="" disabled selected>Select Category</option>
...
<input type="submit" name="submit" style="width:20%;padding:15px;" value="Update"</input>
...</form>

还有两件事你应该注意

  1. onchange="document.form.submit();" this will not work because document doesn't have a property form it is forms so you should use onchange="document.forms[0].submit();"

  2. You have named your submit button as submit which will prevent the form from submitting because submit is a javascript function so rename your submit button to something else.

关于javascript - 如何通过表单提交传递下拉列表的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com