• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to put "command" in the button?

 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day!

I have a page which has two buttons. One is Reset and the other one is Read. When the button Read is pressed, it must send a string "READ" to a servlet. Is this possible?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If by "send" you mean to send as part of the submission, just create a hidden form element that contains your string and the appropriate request parameter name.

Perhaps something like:

 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either use a hidden field as Bear proposes, but you can also make your button behave that way using:

<button type="submit" name="command" value="READ">Read</button>
or
<input type="submit" name="command" value="READ" />
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your replies:

I followed your advice and what I did is this:



then, to determine what button is clicked, I inserted this Javascript:



I tried to pass it to a servlet but it didn't work:

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is because the buttons are performing their default action. Either cancel the btton click by returning false, or change them to plain old buttons.

Eric
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i do that?
[ September 25, 2007: Message edited by: Darren Alexandria ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic