• 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 buttons in a form

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seethis tip from Ted Husted.
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic