• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to recognize that which button is pushed

 
gaurav chhabra
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
 
Hareesh Ram Chanchali
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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic