File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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?

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Valentin Crettaz
Gold Digger
Sheriff

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>
or
<input type="submit" name="command" value="READ" />


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[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
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Aug 17, 2007
Posts: 185
How can i do that?
[ September 25, 2007: Message edited by: Darren Alexandria ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to put "command" in the button?
 
Similar Threads
question to authors of "Mastering Java Server Faces" book
Threads search help
Constructor Chaining
URLyBird - 48 hours and old entries - what do you think ?
JRadioButton : Deselecting