• 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

how to recognize that which button is pushed

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir
like i have several buttons in my webpage then how to recognize that which button is pressed if i like to respond differently when different button is pushed.
thank you
gaurav
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

buttons may be different but the button with SUBMIT type within a form will be considered for method (GET or POST). all other u can write as u wish. do not forget that they it should be in <FORM> </FORM> tag
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The one that's not null is the one that was pressed.




The other approach, which I like less, is to give all the buttons the same name and read the value of the button.


I like this less because the value of a button is the text that the user sees. It's part of the view and shouldn't be used to govern the controller.

No matter what value you give to your buttons, inevitably, either a pony tailed web designer or a pointy haired boss will HAVE to change it. If the text is 'Enter' they will need to change it to 'Saved'. It may also need to be internationalized. In any case, when the text is changed, your servlet will break.

For this reason I prefer to test the name of the button not the value.

Another gotcha, if the user fills out the form and pressed the "Enter" key on the keyboard, the browser will pick the first submit button with both a name and a value and send that as the button that has been pressed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic