473,394 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Repeated field names in a form... Standard behavior?

Hi,
I'm not entirely sure this is the right group to ask this question, but I saw a similar one above, and the group's
charter is not clear enough about it, so, here I go: ;)

What is the standard behavior (if any) when the same name is attached to more than one field in a <form>?

An example (that closely resembles the problem I'm working on) will be (this is a standard radio group without a
default selected option):
<form ...>
<input type="radio" name="Q1" value="1"> opt 1
<input type="radio" name="Q1" value="2"> opt 2
...
<input type="radio" name="Q1" value="n"> Don't know
</form>
The idea is that, in our context "Don't know" and "Don't answer" are very different things, so we want to keep track
of both possibilities. Off course, adding a "Don't Answer" option, selected by default, looks odd as we are forcing the user
to actually give an answer. So "Don't Answer" should be actually that: leaving the question unanswered.

If the user only clicks "submit" we won't get any value for the field "Q1", what is the right behavior as there wasn't
a selected option.

Now, I have discovered that, if I add:

<input type="hidden" name="Q1" value="NoAns">

Right after the <form ...> tag, I get "NoAns" if the user didn't make a choice, and the value associated with the
selected option if she did. This holds for all the browsers I have tried so far (IE6, NN7, NN4, Opera 7). Nevertheless, I'm
not sure if this is the standard behavior (to send back the last value associated with the field name), and I've been unable
to find anything on the web about this type of situations (maybe I didn't look in the right place so a pointer to some source
of information will be a nice answer).
I reckon that it's probably a bad idea to replicate field names in a form (even more if they are of different
'types') but the alternative way through this problem (to add a hidden field with a list of the questions included in the page
and then modifying the associated CGIs to explicitly scan for those questions) will require major surgery in the whole project
something we cannot afford right now... :)

Thanks a lot, and please, *do* let me know if this question is off-topic, I don't want to make your lives miserable.
Andres.

--
Jul 20 '05 #1
10 2828


Andres Eduardo Hernando wrote:

What is the standard behavior (if any) when the same name is attached
to more than one field in a <form>?


Check
http://www.w3.org/TR/html4/interact/...html#h-17.13.2
and maybe
http://www.w3.org/TR/html4/interact/forms.html#radio
if you have several <input type="radio" name="radioName" ...> in one
form then these form a group of mutually exclusive buttons of which only
one can be checked at a time and consequentially only one can be
successful and submitted. For other controls if you have several with
the same name then for each sucessful control the name=value pair is
submitted.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Andres Eduardo Hernando <he******@ls02.fas.harvard.edu> wrote in message news:<bu**********@news.fas.harvard.edu>...
What is the standard behavior (if any) when the same name is attached
to more than one field in a <form>?
It appears that all successful controls are meant to be submitted in
the form data set, even if they share the same name.
An example (that closely resembles the problem I'm working on) will be
(this is a standard radio group without a default selected option)
[snip]
RFC 1866 says:

"At all times, exactly one of the radio buttons in a set is checked.
If none of the <INPUT> elements of a set of radio buttons specifies
`CHECKED', then the user agent must check the first radio button of
the set initially."

So one radio button should be selected, although most user agents
don't honour this requirement.
If the user only clicks "submit" we won't get any value for the field "Q1",
what is the right behavior as there wasn't a selected option.


Although there should be according to RFC 1866...

You technique will probably work, although it is relying on
non-standard behaviour.

--- Safalra (Stephen Morley) ---
http://www.safalra.com/hypertext
Jul 20 '05 #3
us****@safalra.com (Safalra) wrote:
Andres Eduardo Hernando <he******@ls02.fas.harvard.edu> wrote in message news:<bu**********@news.fas.harvard.edu>...
What is the standard behavior (if any) when the same name is attached
to more than one field in a <form>?
It appears that all successful controls are meant to be submitted in
the form data set, even if they share the same name.
An example (that closely resembles the problem I'm working on) will be
(this is a standard radio group without a default selected option)
[snip]


RFC 1866 says:

"At all times, exactly one of the radio buttons in a set is checked.
If none of the <INPUT> elements of a set of radio buttons specifies
`CHECKED', then the user agent must check the first radio button of
the set initially."

So one radio button should be selected, although most user agents
don't honour this requirement.
If the user only clicks "submit" we won't get any value for the field "Q1",
what is the right behavior as there wasn't a selected option.


Although there should be according to RFC 1866...


Which is the specification for HTML 2, which was superseded four years
ago by HTML 4, which states, "If no radio button in a set sharing the
same control name is initially "on", user agent behavior for choosing
which control is initially "on" is undefined." For example, IE 6
doesn't select any of the choices if none of them has a CHECKED
attribute.

You technique will probably work, although it is relying on
non-standard behaviour.

--- Safalra (Stephen Morley) ---
http://www.safalra.com/hypertext

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 20 '05 #4
On Sat, 17 Jan 2004, Safalra wrote:
It appears that all successful controls are meant to be submitted in
the form data set, even if they share the same name.


They're intended to be actually submitted as separate name=value
pairs, indeed, even when some names are the same.

But if your forms evaluation script uses (as certainly /should/ use)
some respected and peer-reviewed module or library - such as CGI.pm in
Perl - to decode the submission parameters, be sure the check its
documentation to see how it will hand these parameters to the program.

As for the detailed issues, what you said wasn't wrong, although the
emphasis on rfc1866 was a bit dated if I might say so ;-)

Might I suggest my page on this topic for another look at the issues,
which aren't all just pedantic detail, some of them do IMHO have real
usability relevance -

http://ppewww.ph.gla.ac.uk/~flavell/www/testradio.html

cheers
Jul 20 '05 #5
Alan J. Flavell <fl*****@ph.gla.ac.uk> wrote:
On Sat, 17 Jan 2004, Safalra wrote:
It appears that all successful controls are meant to be submitted in
the form data set, even if they share the same name.

They're intended to be actually submitted as separate name=value
pairs, indeed, even when some names are the same. But if your forms evaluation script uses (as certainly /should/ use)
some respected and peer-reviewed module or library - such as CGI.pm in
Perl - to decode the submission parameters, be sure the check its
documentation to see how it will hand these parameters to the program.


Just a few words, to summarize what I've learned with this thread and a little of experimentation:

1. All the successful controls *are* actually submitted (at least, in IE6, NN7, and OPERA7 that I have tested).

2. The trick is in the script size. In CGI.pm (what I am using), multivalued parameters contain all the associated values in
an array (that's in the documentation) but in reverse order (that's not in the documentation!, in fact, it should be the
opposite, I quote: "As of version 1.5, the array of parameter names returned will be in the same order as they were submitted
by the browser. Usually this order is the same as the order in which the parameters are defined in the form (however, this
isn't part of the spec, and so isn't guaranteed)."). But, putting a hidden input *before* the radio group works in the
other way:

If I write:
<input type="hidden" name="group1" value="NoAns">
<!- Radio group also named "group1" ->

and then force the parameter to return the whole list of values:

join(';',$query->param("group1"))

Returns:
"NoAns" if the user didn't selected an option in the radio group.
"X; NoAns" if the user selected the option with value X.

Hence, treating the parameter as single-valued returns "NoAns" in the first case and "X" in the second case.

3. Nevertheless, the above behavior relies in the browsers submitting the "name=value" pairs in the same order they are in
the form. Since that's not in the spec, I cannot count with it. So, I'll need to change my scripts.

4. It is advisable to always put a "CHECKED" option in the radio groups as different specs have changed what the browsers
should do when it's absent... If I only could convince my coauthors of this need!... :(
Thanks a lot for all the answers,
Andres.

--
Jul 20 '05 #6
Andres Eduardo Hernando <he******@ls02.fas.harvard.edu> wrote:
opposite, I quote: "As of version 1.5, the array of parameter names returned will be in the same order as they were submitted
by the browser. Usually this order is the same as the order in which the parameters are defined in the form (however, this
isn't part of the spec, and so isn't guaranteed)."). But, putting a hidden input *before* the radio group works in the


Ooops! That's the wrong quote... But I guess you got the idea.

Andres.
--
Jul 20 '05 #7
Andres Eduardo Hernando <he******@ls02.fas.harvard.edu> writes:
The idea is that, in our context "Don't know" and "Don't
answer" are very different things, so we want to keep track of both
possibilities. Off course, adding a "Don't Answer" option, selected
by default, looks odd as we are forcing the user to actually give an
answer. So "Don't Answer" should be actually that: leaving the
question unanswered.


I would say that you definitely *should* include an explicit 'No
answer' as the default state.

On common graphical browsers, if no radio button in a group has
'checked="checked"' then none start selected, and so none get submitted.

If a user then selects one, there is no way for them to go back to
selecting none again _without reloading the page_. Therefore if they
accidentally click 'yes' when they meant 'no answer' they can't easily
change their minds if there's no explicit 'no answer' button.

--
Chris
Jul 20 '05 #8
On 19 Jan 2004 12:54:22 +0000, Chris Morris <c.********@durham.ac.uk>
wrote:
Andres Eduardo Hernando <he******@ls02.fas.harvard.edu> writes:
The idea is that, in our context "Don't know" and "Don't
answer" are very different things, so we want to keep track of both
possibilities. Off course, adding a "Don't Answer" option, selected
by default, looks odd as we are forcing the user to actually give an
answer. So "Don't Answer" should be actually that: leaving the
question unanswered.


I would say that you definitely *should* include an explicit 'No
answer' as the default state.

On common graphical browsers, if no radio button in a group has
'checked="checked"' then none start selected, and so none get submitted.

If a user then selects one, there is no way for them to go back to
selecting none again _without reloading the page_. Therefore if they
accidentally click 'yes' when they meant 'no answer' they can't easily
change their minds if there's no explicit 'no answer' button.

Perhaps - and this is off the cuff - setting a "display: none;" class to
the radio button with the No Answer value set checked...
Jul 20 '05 #9
Neal <ne*****@spamrcn.com> writes:
On 19 Jan 2004 12:54:22 +0000, Chris Morris <c.********@durham.ac.uk>
I would say that you definitely *should* include an explicit 'No
answer' as the default state.

On common graphical browsers, if no radio button in a group has
'checked="checked"' then none start selected, and so none get submitted.

If a user then selects one, there is no way for them to go back to
selecting none again _without reloading the page_. Therefore if they
accidentally click 'yes' when they meant 'no answer' they can't easily
change their minds if there's no explicit 'no answer' button.


Perhaps - and this is off the cuff - setting a "display: none;" class
to the radio button with the No Answer value set checked...


What benefit would that give? I've not tested it, but the most likely
result is that it wouldn't display that radio button, which means that
if you *do* click on another one, you can't click back to 'no answer'
because you can't see it to click on. Might as well not include it at
all and save some bytes in that case (unless your aim is to convince
people to turn off CSS support in their browsers and/or switch
browsers to one without CSS support).

--
Chris
Jul 20 '05 #10
Harlan Messinger <hm*******************@comcast.net> wrote:
Which is the specification for HTML 2, which was superseded four
years ago by HTML 4, which states, "If no radio button in a set
sharing the same control name is initially "on", user agent
behavior for choosing which control is initially "on" is
undefined."


That's rather obscure, since it means that the HTML 2 type behavior is
allowed, and the behavior of not having any button "on" is allowed
(though a pedant might claim otherwise - "which control" might be seen
as implying that one of them is initially "on"), _and_ a browser might
make the last button "on" by default, or something else. I don't think
they really meant that. They just couldn't decide between two behaviors
and allowed both, without realizing what else became permitted.

But it's a strong reason to always include an initially selected radio
button into each group of radio buttons. It's strange that authors miss
this simple principle.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

Jul 20 '05 #11

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

Similar topics

7
by: JDS | last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to JavaScript: I have a long, dynamically-generated form questionnaire. Not all of the form fields are dynamically...
3
by: Keith Wilby | last post by:
I have a form which allows both form and datasheet views. My question is, is it possible to control the field (column) names in datasheet view? What happens at the moment is that the name is...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
6
by: marktxx | last post by:
Although the C90 standard only mentions the use of 'signed int' and 'unsigned int' for bit-fields (use 'int' at your own risk) and C99 adds _Bool. It seems that most compilers create the size of...
7
by: mcha226 | last post by:
Hi All I have to build a page which includes a select element (as a drop down menu) with all the country names in it. However I just found out that the need to be repeated many times so the...
6
by: Guy Macon | last post by:
While I agree with the sentiment, the oringinal title on this thread ("OT: Specially for , why you should always use example.com for obfuscating domains") is wrong. There are other reserved domain...
9
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.