aspose file tools*
The moose likes Struts and the fly likes Multiple buttons in a form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Multiple buttons in a form" Watch "Multiple buttons in a form" New topic
Author

Multiple buttons in a form

Bianca Deloso
Greenhorn

Joined: Sep 23, 2003
Posts: 15
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

Joined: Jul 02, 2003
Posts: 226
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

Joined: Sep 23, 2003
Posts: 15
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

Joined: Oct 26, 2000
Posts: 188
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


My theory of evolution is that Darwin was adopted. - Steven Wright
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

Seethis tip from Ted Husted.


Junilu - [How to Ask Questions] [How to Answer Questions]
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
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

Joined: Jun 29, 2001
Posts: 192
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:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Multiple buttons in a form