• 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

do I have to use javascript to put multiple buttons on one JSP page ?

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my JSP page, I want to have three buttons: one for "submit", one for "renew", one for "delete". clicking on one of them will trigger different action and different next page flow.

1) Should I use one or multiple FORM on this JSP page ?
2) how can I implement 3 buttons on one page ? how do they map to the "ACTION" element if there is only ONE FORM ?

confusing...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's probably simpler to have just one form, because there are usually other fields in the form that need to be submitted as well. Those would otherwise need to be duplicated.
Yes, it's possible to have multiple buttons in a form. Instead of making them submit buttons (ie.e, type=submit), you would use type=button and have them call JavaScript functions, which would then set the action value of the form to something appropriate for that button and submit the form.
 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can have any number of submit buttons in a single form. You can distinguish them by having different values for the name attribute for each of them.

There are two ways you can handle having different actions for different buttons:

1. Handle the logic at the server side
You can have some sort of a controller servlet and when the request comes in, based on the button clicked, forward the request to the servlet you want.

2. Handle it using javascript
Have a javascript function called in the onSubmit attribute of the form. There based on the button clicked, you can change the action value of the form using
When the browser submits the page, it will submit to the action you set in your javascript function, regardless of what you had initially specified while defining your form.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a thing to do with JSP, so moved to HTML/Javascript.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic