GeeCON Prague 2014*
The moose likes Servlets and the fly likes how to get values from checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "how to get values from checkbox" Watch "how to get values from checkbox" New topic
Author

how to get values from checkbox

muthukumaran mohan
Greenhorn

Joined: Oct 09, 2001
Posts: 7
Hi all,
how to get values from checkbox. assume that i have two checkbox and i want to check which checkbox is selected and which one is not selected.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
correct me if i'm wrong anyone but if your checkbox was checked when the form was submitted, it will appear in the request as a name/value pair.
if it wasn't checked, it won't appear at all.

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Adam, you are correct. Muthukumaran, if you use getParameter(yourCheckBoxName), and null is returned it means that checkbox was not checked. Else, the checkbox is checked, and it should return the corresponding value for that checkboxname.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
muthukumaran mohan
Greenhorn

Joined: Oct 09, 2001
Posts: 7
thank you Adam, can you clear me in detail, my query is that i want to store yes or no when the checkbox is clicked or not clicked.
awaiting for your early reply.
bye for now.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Ad I posted earlier, In your request.getParameter(yourCheckBoxName) if it returns null, it means it's not clicked. Else, it's clicked. Store your values baased on this. Am I missing something here???

Bosun
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
if you want a code snippet:
 
GeeCON Prague 2014
 
subject: how to get values from checkbox