This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Servlets and the fly likes Processing Radio Buttons in a Form/Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Processing Radio Buttons in a Form/Servlet" Watch "Processing Radio Buttons in a Form/Servlet" New topic

Processing Radio Buttons in a Form/Servlet

Vasha Qafiri

Joined: Jan 23, 2001
Posts: 3
Hi all,
I have a form, with a table. On each row of the table there is an "and" and "or" radio button.
First, I only want the user to select one radio button per row. That is if they select "and", then "or" becomes disabled. I tried to solve this by naming both radio buttons the same name, but then I can only choose 1 radio button on the form, not for each row.
Second, I would like to know what they selected in my servlet. I have something like this
String[] choice = req.getParameterValues("and_or");
String val;
for (int i=0; i<4;i++)
val = choice[i];
Sandeep Agarwal

Joined: Jan 23, 2001
Posts: 2
U will have to use differnt name for each set of radio button on the rows..

Then String x1=this will get the value of the selected radio button
x2=getParameterValue(<button name2> ) for seond button
Danny Mui
Ranch Hand

Joined: Dec 14, 2000
Posts: 42
the radio buttons with the same name will only allow you to choose one value from it. so if you label them all with the same name, only one choice will be made
so, each row has to have a diff radio button set name
<td><input type="radio" name="row1" value="and"><...put or here here ..></td>
<td><input type="radio" name="row2" value="and"><...put or here here ..></td>
you don't need getParameterValues() for radio buttons, only for multiple entries..
so assuming the rows are labeled in sequential order (if there is no value, i'm done)...
this should retrieve what you need
String and_or;
for (int i = 1; (and_or = request.getParameter("row"+i)) != null ;i++){
//and_or is set to whatever it is, and or or hehe
hope that helps a tad!
if not, i'll go hide now.

[This message has been edited by Danny Mui (edited January 23, 2001).]
[This message has been edited by Danny Mui (edited January 23, 2001).]
eric clark

Joined: Jan 18, 2001
Posts: 16
to get the values if buttons are selected or not, ya simply could do the following, that werked for me:
String paraname = "";
for (Enumeration selectedValues = request.getParameterNames();selectedValues.hasMoreElements(); ) {
paraname = selectedValues.nextElement().toString();
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Processing Radio Buttons in a Form/Servlet
It's not a secret anymore!