Html 如何提交更改下拉列表的表单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7231157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to submit form on change of dropdown list?
提问by John
I am creating a page in JSP where I have a dropdown list and once the user selects a value he has to click on the go button and then the value is sent to the Servlet.
我正在 JSP 中创建一个页面,其中有一个下拉列表,一旦用户选择了一个值,他必须单击 go 按钮,然后将该值发送到 Servlet。
</select>
<input type="submit" name="GO" value="Go"/>
How do I make it so that it does it on change? E.g. when the user selects John all his details are retrived from the DB and displayed. I want the system to do it without having to click the go button.
我如何制作它以便它在更改时执行?例如,当用户选择 John 时,他的所有详细信息都会从数据库中检索并显示出来。我希望系统无需单击执行按钮即可执行此操作。
回答by BalusC
Just ask assistance of JavaScript.
只需请求 JavaScript 的帮助。
<select onchange="this.form.submit()">
...
</select>
See also:
也可以看看:
回答by MD Sayem Ahmed
Simple JavaScript will do -
简单的 JavaScript 就可以了——
<form action="myservlet.do" method="POST">
<select name="myselect" id="myselect" onchange="this.form.submit()">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
</select>
</form>
Here is a link for a good javascript tutorial.
这是一个很好的javascript 教程的链接。
回答by sate wedos
other than using this.form.submit()
you also submiting by id or name.
example i have form like this : <form action="" name="PostName" id="IdName">
除了使用this.form.submit()
您之外,您还可以通过 id 或 name 提交。例如我有这样的表格:<form action="" name="PostName" id="IdName">
By Name :
<select onchange="PostName.submit()">
By Id :
<select onchange="IdName.submit()">
按名字 :
<select onchange="PostName.submit()">
通过 ID :
<select onchange="IdName.submit()">
回答by nitsram
To those in the answer above. It's definitely JavaScript. It's just inline.
对于上面答案中的那些人。这绝对是 JavaScript。它只是内联。
BTW the jQuery equivalent if you want to apply to all selects:
顺便说一句,如果您想应用于所有选择,则等效于 jQuery:
$('form select').on('change', function(){
$(this).closest('form').submit();
});