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 isjavascript
, 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
3 Answers
Reset to default 2I 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
评论列表(0条)