JSP:同一个表单上有两个提交按钮
我在 JSP 页面中的同一表单上有两个提交按钮,根据具体情况,每个按钮都会出现在表单中。
问题是其中一个提交按钮提交表单,而另一个则不提交。
这是 HTML 表单
<form name="stdActivationForm" id="stdActivationForm" action="ParentManagementServlet" method="post" onsubmit="return validateStudentActivationForm()">
<input class="${isActivated? 'hideDiv':'showDiv'}" type="submit" value="confirm" name="submit" onclick="submitForm('add')"/>
<input class="${parent != null? 'showDiv':'hideDiv'}" type="submit" value="update" name="submit" onclick="submitForm('update')"/>
</form>
,这是 javascript 函数
function submitForm(btnName)
{
var form = document.getElementById("stdActivationForm");
if (btnName =='add')
document.form.submit();
else if(btnName =='update')
document.form.submit();
}
I have two submit buttons on the same form in JSP page, one of each appear in the form depending on the case.
The problem is that one of the submit buttons submit the form, and the other does not .
here's the HTML form
<form name="stdActivationForm" id="stdActivationForm" action="ParentManagementServlet" method="post" onsubmit="return validateStudentActivationForm()">
<input class="${isActivated? 'hideDiv':'showDiv'}" type="submit" value="confirm" name="submit" onclick="submitForm('add')"/>
<input class="${parent != null? 'showDiv':'hideDiv'}" type="submit" value="update" name="submit" onclick="submitForm('update')"/>
</form>
and here's the javascript function
function submitForm(btnName)
{
var form = document.getElementById("stdActivationForm");
if (btnName =='add')
document.form.submit();
else if(btnName =='update')
document.form.submit();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你的 JavaScript 函数需要返回 true。
或者,您可以删除 onclick 引用,它应该仅适用于 type="submit"。
祝你好运。
I think your JavaScript function needs to return true.
Alternatively you can just remove the onclick reference and it should work with just type="submit".
Good luck.
摆脱
onclick
。你在这里不需要它。type="submit"
已提交表单。您的具体问题可能是由于Get rid of the
onclick
. You don't need it here. Thetype="submit"
already submits the form. Your concrete problem is likely caused because theonsubmit
of the<form>
has returnedfalse
.尝试将按钮的输入类型更改为
"button"
并将方法更改为:无论如何,两个按钮当前都提交到同一个 Servlet。
Try changing the input type of the buttons to
"button"
and the method to:Both buttons are currently submitting to the same Servlet anyway.