• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp form with two submit button

 
Greenhorn
Posts: 29
Netbeans IDE Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps this article might help.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic