Reputation: 9878
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();
}
Upvotes: 0
Views: 8517
Reputation: 22481
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.
Upvotes: 0
Reputation: 1109655
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
.
Upvotes: 2
Reputation: 4999
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.
Upvotes: 2