• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Processing Radio Buttons in a Form/Servlet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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];
}
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic