0

I'm trying to retrieve the value of a radio button in a servlet but im getting ON for the ones i have selected and Null for the ones i have not selected. I'm not getting the values. Please do help me out.

The Servlet

for(int i=0;i<itemnode.getLength();i++){
            ans[i] = request.getParameter(Integer.toString(i));
            System.out.println(ans[i]);
        }

The html page :

<input type="radio" name="1" value="1" style="float: left;">
<input type="radio" name="1" value="2" style="float: left;">
<input type="radio" name="1" value="3" style="float: left;">
<input type="radio" name="1" value="4" style="float: left;">

<input type="radio" name="2" value="1" style="float: left;">
<input type="radio" name="2" value="2" style="float: left;">
<input type="radio" name="2" value="3" style="float: left;">
<input type="radio" name="2" value="4" style="float: left;">

The output at console:

null
on

Null for the ones i have not selected and On for the ones i have selected

sek har
  • 17
  • 6
  • *sidenote:* radio button does not require `float: left`; it already aligns in a row – Raptor Sep 04 '13 at 10:47
  • names should be different for all radio button. – Ved Sep 04 '13 at 10:50
  • 1
    @Ved, no, it is crucial that radio buttons that form a group share the same name. And a radio button without a group is like a list member without a list. – Jukka K. Korpela Sep 04 '13 at 10:51
  • @ShivanRaptor That is the css i have used for the radio buttons but that is ignorable, what i wanted is why is the value not coming in servlet. – sek har Sep 05 '13 at 07:47

0 Answers0