"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