JSP:同一个表单上有两个提交按钮

发布于 2024-11-04 02:57:59 字数 958 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伤感在游骋 2024-11-11 02:57:59

我认为你的 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.

傲世九天 2024-11-11 02:57:59

摆脱onclick。你在这里不需要它。 type="submit" 已提交表单。您的具体问题可能是由于

onsubmit 返回 false 引起的。

Get rid of the onclick. You don't need it here. The type="submit" already submits the form. Your concrete problem is likely caused because the onsubmit of the <form> has returned false.

§普罗旺斯的薰衣草 2024-11-11 02:57:59

尝试将按钮的输入类型更改为 "button" 并将方法更改为:

function submitForm(btnName)
{
   // skip validation for updates, remove btnName =='add' && when it is working
   if (btnName =='add' && !validateStudentActivationForm())
   {
     return;      
   }   
   document.forms["stdActivationForm"].submit();
}

无论如何,两个按钮当前都提交到同一个 Servlet。

Try changing the input type of the buttons to "button" and the method to:

function submitForm(btnName)
{
   // skip validation for updates, remove btnName =='add' && when it is working
   if (btnName =='add' && !validateStudentActivationForm())
   {
     return;      
   }   
   document.forms["stdActivationForm"].submit();
}

Both buttons are currently submitting to the same Servlet anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文