top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How do I handle FORMs with multiple form elements (e.g. radio buttons) using the same name?

+3 votes
345 views
How do I handle FORMs with multiple form elements (e.g. radio buttons) using the same name?
posted Nov 20, 2015 by Shyam

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

For radio buttons, the HTML spec assumes that a given group of buttons will have the same NAME and different VALUEs; the browser makes sure that only one button per group name will be selected (at most). So you can just call request.getParameter(“groupname”).

<input type="radio" name="topping" value="cheese" checked>Cheese
<input type="radio" name="topping" value="pepperoni">Pepperoni
<input type="radio" name="topping" value="anchovies">Anchovies

If the user selects “Pepperoni” then request.getParameter(“topping”) will return the string “pepperoni”.
For lists using the

   Name 1: <input type="text" name="name" value="Dick">
   Name 2: <input type="text" name="name" value="Jane">
answer Nov 23, 2015 by Karthick.c
...