简体   繁体   English

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

[英]JSP: two submit button on the same form

I have two submit buttons on the same form in JSP page, one of each appear in the form depending on the case.我在 JSP 页面的同一表单上有两个提交按钮,每个按钮都会根据情况出现在表单中。

The problem is that one of the submit buttons submit the form, and the other does not.问题是其中一个提交按钮提交表单,而另一个没有。

here's the HTML form这是 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>

and here's the javascript function这是 javascript function

  function submitForm(btnName)
        {
            var form = document.getElementById("stdActivationForm");
            if (btnName =='add')
                document.form.submit();
            else if(btnName =='update')
                document.form.submit();
        }

I think your JavaScript function needs to return true.我认为您的 JavaScript function 需要返回 true。 Alternatively you can just remove the onclick reference and it should work with just type="submit".或者,您可以只删除 onclick 参考,它应该只使用 type="submit"。

Good luck.祝你好运。

Get rid of the onclick .摆脱onclick You don't need it here.你在这里不需要它。 The type="submit" already submits the form. type="submit"已经提交了表单。 Your concrete problem is likely caused because the onsubmit of the <form> has returned false .您的具体问题可能是由于<form>onsubmit返回false引起的。

Try changing the input type of the buttons to "button" and the method to:尝试将按钮的输入类型更改为"button" ,并将方法更改为:

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.无论如何,这两个按钮当前都提交给同一个 Servlet。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM