aspose file tools*
The moose likes Servlets and the fly likes multiple submit buttons  and jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "multiple submit buttons  and jsp" Watch "multiple submit buttons  and jsp" New topic
Author

multiple submit buttons and jsp

Yogesh GA
Greenhorn

Joined: Apr 09, 2001
Posts: 6
I have a form that displays user groups ..and two buttons - one to Add new user groups and the other to delete existing user groups.the portion that displays the user groups on the form is same for both these actions. on clicking on these buttons each calls a different jsp file to do the respective task ..now my question is though i have made both the buttons a submit button how to have two different action attributes on the same form..have any one of u encountered such a need and what are the ways of going abt. it ?
I dont want to make it a hyperlink...
Pls send me the code and any links ..pls help ..it is very urgent
thanks all
Yogesh
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
One way is to replace those buttons by cheerful images that don't just look cool, but also cause the browser to pass the coordinates (as in a server-side imagemap) as part of the request. The parameter names are "imagename.x" and "imagename.y". The image name will tell you which submit "button" was clicked.
If you want to stick to buttons, you might add onClick JavaScript handlers to both buttons which modify form.action (or a hidden field on the form) depending on the button clicked. I'm not enough of a JavaScript guru to tell how browser-dependent this is.
- Peter

[This message has been edited by Peter den Haan (edited May 18, 2001).]
Thomas Baumann
Greenhorn

Joined: May 02, 2001
Posts: 10
Hi Yogesh,
you can put each submit into a separate form-tag, e.g.:
..
<form name="firstaction" action="firstaction" method=post>
<input type=submit value="firstactionvalue">
</form>
..
<form name="secondaction" action="secondaction" method=post>
<input type=submit value="secondactionvalue" >
</form>
..
Raja Shekhar
Ranch Hand

Joined: Apr 02, 2001
Posts: 49
Hi
Just call java Scrupt finctions on clickin the button
and specify differtrent actions..
Carry On
Raj
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Or have the action for both be a single servlet which checks which named submit button was clicked and redirects to the appropriate jsp.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
great veera
Greenhorn

Joined: May 14, 2001
Posts: 24
But Frank he has to make compromise on the performance,having two form is the ideal solution for his question,what raj suggessted is not for two submit button ,thats for two ordinary buttons.....
cheers.
gv
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
You have to be very careful if you use multiple forms rather than multiple submit buttons in one form. Different browsers lay out forms in very different ways, and if you would like to have both buttons on the same line of the page, then it may not be possible with multiple forms. Make sure you test your look-and feel with at least IE, Netscape 4, Netscape 6 and Opera and don't assume that because one browser does what you expect they all will.
Adding a servlet controller shouldn't have a significant performance impact anyway. The Servlet API explicitly provides a way to forward directly to a local JSP or servlet with no extra network traffic.
Yogesh GA
Greenhorn

Joined: Apr 09, 2001
Posts: 6
Hi all,
thanks to all for replying..i tried with a single form and 3 submit buttons..i modified the action attribute with a javascript function and it works great!! i will also try with the servlet solution..i am putting here the javasript code for all ...
<script language="javascript">
function adjust(obj)
{
if(obj.name == "B1")
{
document.test.action = "http://appsr/webapp/Dacs/Login.html";
alert("b1 was clicked");
return true;
}
if(obj.name == "B2")
{
document.test.action = "http://appsr/webapp/Dacs/left.html";
alert("b2 was clicked");
return true;
}
if(obj.name == "B3")
{
document.test.action = "http://appsr/webapp/Dacs/right.html";
alert("b3 was clicked");
return true;
}
}
</script>
</head>
<body>
<form name=test method="POST" action="">
<p align="center"><font face="Arial">Click one of these</font></p>
<p> </p>
<p align="center"><input type="submit" value="Submit1" name="B1" onClick="return adjust(this);">
<input type="submit" value="Submit2" name="B2" onClick="return adjust(this);">
<input type="submit" value="Submit3" name="B3" onClick="return adjust(this);">
<input type="reset" value="Reset" name="B4"></p>
</form>
</body>
</html>

bye,
Yogesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiple submit buttons and jsp
 
Similar Threads
Problem in DispatchAction
Values in multiple tiles
hidden parameter quesion in JS
2 forms in a page?
I want to add the two submit button in the same form?