开发者

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.

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.fo开发者_如何学Crm.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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜