This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp form with two submit button

 
satheesh subramani
Greenhorn
Posts: 29
Fedora Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i want two submit buttons ok1 and ok2 if the user click ok1 control goes with 1.jsp or
click ok2 control goes with 2.jsp but ok2 is not working.

is there any mistake two submit buttons then what are methods to resolve


my code is here

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="1.jsp" method="post">
<table>
<tr>
<td>
<input type="text" name="textbox">
</td>
</tr>
<tr>
<form action="2.jsp" method="post">
<table>
<tr>
<td>
<input type="text" name="textbox2">
</td>
</tr>
<tr>
<td>
<input type="submit" value="ok2">
</td>
</tr>
</table>
</form>
</tr>
<tr>
<td>
<input type="submit" value="ok1">
</td>
</tr>
</table>
</form>

</body>
</html>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
 
satheesh subramani
Greenhorn
Posts: 29
Fedora Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Mohamed Hegab
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use 2 buttons with onclick event in each one

<input type="button" onclick="gotopage1();" value="ok1"/>
<input type="button" onclick="gotopage2();" value="ok1"/>

and make the two deffrent functions in the javascript side with collecting the form data by jquery or something
 
Christophe Porteneuve
Author
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Mohamed,

First off, you can't nest forms in HTML. That's not valid and won't work.

If you want a single form to change its actions (its target page) depending on which submit is used, the only way you can achieve that is through JS (so if JS is not guaranteed or you need good accessibility, that's going to be an issue at some point).

Basically you need to map the markup-specified action to the one for the first submit in document order (so other ways of submitting your form, e.g. hitting Return in a non-capturing field, work properly). Then you observe click on the second submit and have it change the form's action property.

Still, this is poor UI design, or poor backend design. Perhaps your backend should look at which submit field got serialized (only the used submit field will get passed to the backend) and act accordingly?

Best,
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Porteneuve wrote:Still, this is poor UI design, or poor backend design. Perhaps your backend should look at which submit field got serialized (only the used submit field will get passed to the backend) and act accordingly?


Agreed. The action attributes of the form elements shouldn't even be JSPs.
 
satheesh subramani
Greenhorn
Posts: 29
Fedora Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi paul,

thanks for your contribution

then you people suggest jsp always have a servlet or something(business logic seperately)
but i don't know
the page carrying some data to another page then why it go to the servlet and go the the jsp page

help elaborate the answer
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps this article might help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic