473,795 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2882


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.ha rvard.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.ha rvard.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="check ed"' 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.********@dur ham.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="check ed"' 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*****@spamrc n.com> writes:
On 19 Jan 2004 12:54:22 +0000, Chris Morris <c.********@dur ham.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="check ed"' 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

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

Similar topics

7
3237
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 generated, though. I'd like to capture the NAME of every HTML form field element on the server, even if that element is submitted blank. The trouble is, with, say, radio buttons or checkboxes for example, a *blank* element does not get submitted at all.
3
6425
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 taken from a control's label if there is one, and if not, the control's name is used. This is confusing for my users so I'd like to be able to use more sensible names in datasheet view. Is this possible? Many thanks. Keith.
18
18421
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 a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
9
3138
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 be inserted into a standard web address in the table (the filed name is link) in ddw1 Example address ---
6
3852
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 the bit-field object from the size used to specify the field. Could this be considered a defacto standard now (at least for 8 bit sized bit-fields)? Any recent compilers not allowing this?
7
3511
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 client can select as many country as they can in their around the world trip planning. I don't want to repeat this long list multiple times, because I want to save bandwidth. Is there a more efficient way to do this rather than using JavaScript to...
6
3113
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 names besides example.com. The search for reserved domain names should start with RFC 2606 ( http://www.faqs.org/rfcs/rfc2606.html ) which defines; *.test *.example
9
3007
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 directory. Assume that all contents of all the files may be held in memory at the same time. Do not use unsafe code blocks and/ or pointers.
9
2521
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 -- comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
0
9672
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
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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
10001
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...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
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
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.