File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Processing Radio Buttons in a Form/Servlet" Watch "Processing Radio Buttons in a Form/Servlet" New topic
Author

Processing Radio Buttons in a Form/Servlet

Vasha Qafiri
Greenhorn

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
Greenhorn

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
<tr>
<td><input type="radio" name="row1" value="and"><...put or here here ..></td>
</tr>
<tr>
<td><input type="radio" name="row2" value="and"><...put or here here ..></td>
</tr>
....
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
Greenhorn

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();
cheers
eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Processing Radio Buttons in a Form/Servlet