• 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

multiple submit buttons and jsp

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
..
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Just call java Scrupt finctions on clickin the button
and specify differtrent actions..
Carry On
Raj
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or have the action for both be a single servlet which checks which named submit button was clicked and redirects to the appropriate jsp.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic