• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple buttons in a form

 
Bianca Deloso
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!
 
Santosh Maskar
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!
 
Eric Fletcher
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
 
Junilu Lacar
Bartender
Pie
Posts: 7752
61
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • 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
 
David Yutzy
tumbleweed and gunslinger
Ranch Hand
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic