aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes jsp form with two submit button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jsp form with two submit button" Watch "jsp form with two submit button" New topic
Author

jsp form with two submit button

satheesh subramani
Greenhorn

Joined: Jan 03, 2011
Posts: 29

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

Joined: Jan 10, 2002
Posts: 61221
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
satheesh subramani
Greenhorn

Joined: Jan 03, 2011
Posts: 29

thanks
Mohamed Hegab
Greenhorn

Joined: Jan 28, 2010
Posts: 11
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

Joined: Jan 28, 2008
Posts: 43
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,


Christophe Porteneuve aka TDD
"They did not know it was impossible, so they did it." --Mark Twain
Pragmatic Guide to JavaScript: http://books.pragprog.com/titles/pg_js/
Prototype and script.aculo.us: http://books.pragprog.com/titles/cppsu/
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jan 03, 2011
Posts: 29

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

Joined: Jan 10, 2002
Posts: 61221
    
  66

Perhaps this article might help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp form with two submit button