473,748 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple groups of radio buttons with same name?

I'm trying to create a dynamic form that can have multiple groups of
radio buttons (each group has two buttons) with the same name.

Essentially, the form allows a user to enter as many names as they
want. If they need to add more, they click an "add name" button and
the javascript inserts another row of input boxes. Each row should
have two radio buttons to indicate sex (M F).

When you have multiple text input boxes with the same name, they get
submitted as an array. Multiple radio buttons with the same name only
submit one value. Unfortunately, I can't give my radio buttons
different names because the user could insert as many names on the
form as he or she wants.

Is there some way around this?
Jul 23 '05 #1
2 3154
th********@hotm ail.com (Jeff) writes:
I'm trying to create a dynamic form that can have multiple groups of
radio buttons (each group has two buttons) with the same name.
Not possible in the way you mean it.
Essentially, the form allows a user to enter as many names as they
want. If they need to add more, they click an "add name" button and
the javascript inserts another row of input boxes.
How does this work without javascript? (I'm not saying it doesn't,
since there are ways to do this that do work without requiring
javascript, but I thought I'd ask)
Each row should have two radio buttons to indicate sex (M F).
Okay.
When you have multiple text input boxes with the same name, they get
submitted as an array. Multiple radio buttons with the same name only
submit one value.
Yes, that's what radio buttons do. One, and only one, can be selected.
Unfortunately, I can't give my radio buttons different names because
the user could insert as many names on the form as he or she wants.
That shouldn't be a problem.
Is there some way around this?


Yes: Give the radio buttons different names!

<input type="radio" name="mf1" value="m" checked='checke d'> Male
<input type="radio" name="mf1" value="f"> Female
<input type="radio" name="mf2" value="m" checked='checke d'> Male
<input type="radio" name="mf2" value="f"> Female
....
<input type="radio" name="mf376" value="m" checked='checke d'> Male
<input type="radio" name="mf376" value="f"> Female

Then it will work as you want. When the form is submitted, note that
there's 12 elements in the text input array, note that this means you
have variables mf1 to mf12 that correspond to them, match them up, and
carry on.

Alternatively you could have <input name='name1'>, <input
name='name2'>, etc. and not bother with the array. Just keep adding
one to your counter until you get to a variable that isn't set.

--
Chris
Jul 23 '05 #2

"Jeff" <th********@hot mail.com> wrote in message
news:1f******** *************** ***@posting.goo gle.com...
I'm trying to create a dynamic form that can have multiple groups of
radio buttons (each group has two buttons) with the same name.

Essentially, the form allows a user to enter as many names as they
want. If they need to add more, they click an "add name" button and
the javascript inserts another row of input boxes. Each row should
have two radio buttons to indicate sex (M F).

When you have multiple text input boxes with the same name, they get
submitted as an array. Multiple radio buttons with the same name only
submit one value. Unfortunately, I can't give my radio buttons
different names because the user could insert as many names on the
form as he or she wants.


Your question is like asking "How can I name all my children George and
then, when I call, "George!", have the right one respond?"

If I understand the point of your last sentence correctly, you think that
you have to have allocated enough names in advance to cover all the fields
the user might add. You don't. This is dynamic, after all. All you need is a
counter to keep track of how many sets of fields (name and sex) are already
on the page, and use that to generate the distinct names you need for each
set of fields added by the user.

var nInputs;
var nameName, sexName, beaconName;
// Hidden field beaconxxx with non-blank value is used by the
server-side code to check for the existence
// of each successive set of entries.
...
// User has requested the insertion of another set of fields.
nInputs++;
textName = "name" + nInputs;
radioName = "sex" + nInputs;
beaconName = "beacon" + nInputs;
document.write "...<input type='text' name='" + nameName + "' ...>...";
document.write "...<input type='radio' name='" + sexName + "' value='M'
....> Male...";
document.write "...<input type='radio' name='" + sexName + "' value='F'
....> Female...";
document.write "...<input type='hidden' name='" + beaconName + "'
value='X'>...";

On the server side (using ASP for this example), you start at 1 and keep
going until you run out of fields to process:

dim iInput;
iInput = 1
dim name, sex, beacon
beacon = Request.Form("b eacon" + iInput)
do until beacon = ""
name = Request.Form("n ame" + iInput)
sex = Request.Form("s ex" + iInput)
...
iInput = iInput + 1
beacon = Request.Form("b eacon" + iInput)
loop
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4080
by: TheKeith | last post by:
I am doing a form for my site and would like to enable and disable a radio button set depending on whether one of the choices on an outer radio button set is checked. How can I refer to all the inputs of the inner radio button set (they all share a common name) with javascript. I tried document.getElementsByNames('thename') but it doesn't work. I know this is because this method returns an array which you must then refer to by a specific...
3
2301
by: elhombrebala | last post by:
With this script I can force the user to select the checkbox befor continuing, but now I have a menu with lots of radio unputs and I woul like the user to select at least 2 of them; how can I check it? <form name=formulario> <INPUT type=checkbox name=casilla> <INPUT type=button value="Salir" onclick="Goingout()"> </form>
2
43552
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as they want. If they need to add more, they click an "add name" button and the javascript inserts another row of input boxes. Each row should have two radio buttons to indicate sex (M F). When you have multiple text input boxes with the same...
3
2072
by: Amelyan | last post by:
When we want radio button to belong to a group name we say, radio1.GroupName="GroupA". In this case, radio1 will be unselected if another radio button is selected in "GroupA". Is there a way (trick, custom RadioButton, or javascript) to make radio button (radio1) belong to 2 independent radio button groups instead of one? This would be an equivalent of sayting something like radio1.GroupName1 = "GroupA"; radio1.GroupName2 = "GroupB";
3
3783
by: Abersparky | last post by:
I'm having a problem with multiple radio button groups within a while loop. I have the page made so it pulls from a database the row values - one of which is a Y or N value. I have a radio button group for the Y and N value for each row of the database that gets pulled but only the last row will populate the value retrieved from the db. I know that I have to create a unique name for the radio buttons for each row - but I don't know how...
2
6802
by: forbes | last post by:
Hi, I have a form that contains multiple groups of checkboxes that act like radio buttons (at the clients insistance). There is one text field that is required and 28 checkbox groups. Here an example of a checkbox group: <td><input type="checkbox" name="trusted" value="1" id="ck_ttt1" onclick="... <td><input type="checkbox" name="trusted" value="2" id="ck_ttt2"
5
7471
stepterr
by: stepterr | last post by:
I have a form that is built based on a query. Everything is working except when I submit the form the radio buttons are only updating the first row in my database. dcategory and dthumbnail are two radio buttons that I have for each one of the rows in the table. I've tried using a hidden input object for each of the radio button groups to store the values in but clearly I'm having a mental block because I can't get that to work right either. So...
3
8044
by: DragonLord | last post by:
Ok here is the situation in detail. Single form with multiple items on it, 4 of which are panls that contain radio butons. Each panel loads it's radio buttons from a list of items in a sql database table. This is the easy part. Hard part is this. The panels are not ll in a row on the form so i can't just put the into a single group box yet I want them all to behave as one. Is there a way that I can programtically tell this windows...
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9332
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.