Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Multiple buttons in a form

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
My page has 4 buttons in one form. One is the submit button, another one is a cancel button, and the other two are buttons that does another action if chosen. (For example, delete and edit).
I use <html:img> or <html:image> tags for the buttons. I was wondering how I could get my action to determine which button was clicked and have the forward subsequently use the right target to forward to.
Any help would be great. Thanks!
Thanks!
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use javascript for determine the wich button is chk
td height="25" align="left">
<a href="javascript:saveRecord()">
<img src="images/ttl_set.gif" name='submit1' border="0" align="absMiddle"/>
</a>
</td>
 
Bianca Deloso
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried out the code but I think I did something wrong. I added two of my buttons with the javascript but when I click on one of them I also pass through the 'action/method' of the other button.
Incidentally, using this means placing the name of the method of a single action in the javascript right?
Thanks!
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bianca,
One way you could do this is to put a property on your action form that is set by a javascript function to identify which button was pressed by the user. So in your action form, add a property called, say, "buttonPressed" or something like that. Create a javascript function that takes the button identifier as an arg, then call this in the onclick property of the button passing the button id in as the arg. The function sets the buttonPressed property, then submits the form, something like this:

You can then put conditional logic in your action to determine the proper forward.
A disclaimer: This assumes that all the buttons are calling one action, the action declared in the form tag.
HTH
E
 
Sheriff
Posts: 15754
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seethis tip from Ted Husted.
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, sorry Bianca, I should have read your post better, I missed the part about the image buttons.
E
 
tumbleweed and gunslinger
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use DispatchAction along with the "method" hidden field to determine which method is called. I can place any number of buttons, images, buttons, etc.
So in the onclick of the button, use this:
Then, as an example of a DispatchAction class is as follows:
 
eat bricks! HA! And here's another one! And a tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic