File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes How to put Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to put "command" in the button?" Watch "How to put "command" in the button?" New topic

How to put "command" in the button?

Darren Alexandria
Ranch Hand

Joined: Aug 17, 2007
Posts: 185
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?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

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:

[Asking smart questions] [About Bear] [Books by Bear]
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
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>
<input type="submit" name="command" value="READ" />

[Blog] [Blogroll] [My Reviews] My Linked In
Darren Alexandria
Ranch Hand

Joined: Aug 17, 2007
Posts: 185
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

Joined: Nov 08, 2001
Posts: 15385
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.

Darren Alexandria
Ranch Hand

Joined: Aug 17, 2007
Posts: 185
How can i do that?
[ September 25, 2007: Message edited by: Darren Alexandria ]
I agree. Here's the link:
subject: How to put "command" in the button?
It's not a secret anymore!