javascript - JSP: two submit button on the same form - Stack Overflow

I have two submit buttons on the same form in JSP page, one of each appear in the form depending on the

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();
        }

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();
        }
Share Improve this question edited Apr 28, 2011 at 18:09 Java Drinker 3,1571 gold badge22 silver badges19 bronze badges asked Apr 28, 2011 at 17:51 palAlaapalAlaa 9,87833 gold badges110 silver badges170 bronze badges 8
  • 1 that is not a JAVA script. that is javascript, two pletely different things.... – Naftali Commented Apr 28, 2011 at 17:52
  • I don't understand use of this javascript function here !! what it is written for ? – Jigar Joshi Commented Apr 28, 2011 at 17:54
  • @Nael,I edit it,thanx. @Jigar Joshi, I found this solution in this roseindia/answers/viewqa/JSP-Servlet/…, but it doesn't work! – palAlaa Commented Apr 28, 2011 at 17:56
  • Of the same problem that I faced. – palAlaa Commented Apr 28, 2011 at 18:00
  • 5 Put roseindia in your blacklist. That site is cluttered of bad practices. – BalusC Commented Apr 28, 2011 at 18:06
 |  Show 3 more ments

3 Answers 3

Reset to default 2

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744895944a4599696.html

相关推荐

  • javascript - JSP: two submit button on the same form - Stack Overflow

    I have two submit buttons on the same form in JSP page, one of each appear in the form depending on the

    2天前
    90

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信