表单中的重复字段名称...标准行为? [英] Repeated field names in a form... Standard behavior?

查看:111
本文介绍了表单中的重复字段名称...标准行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我不完全确定这是一个提出这个问题的合适人选,但我看到上面有类似的一个,而且这个小组是'

章程对它不够清楚,所以,我在这里:;)


当同一名称附加到多个字段时,标准行为(如果有的话)是什么?在一个< form>?

一个例子(与我正在研究的问题非常相似)将是(这是一个标准的无线电组,没有

默认选择选项):

< form ...>

< input type =" radio"名称= QUOT; Q1"值= QUOT 1 QUOT;> opt 1

< input type =" radio"名称= QUOT; Q1"值= QUOT; 2英寸;> opt 2

...

< input type =" radio"名称= QUOT; Q1"值= QUOT; N">不知道

< / form>

这个想法是,在我们的背景下不知道和不要回答是非常不同的东西,所以我们想跟踪这两种可能性的b $ b。当然,添加不要回答默认情况下选择的选项看起来很奇怪,因为我们强迫用户

来实际给出答案。所以别回答实际上应该是这样:让问题无人接听。


如果用户只点击提交我们不会为该领域获得任何价值Q1,这是正确的行为,因为没有选择
a选项。


现在,我发现,如果我添加:


< input type =" hidden"名称= QUOT; Q1" value =" NoAns">


< form ...>之后标签,我得到NoAns如果用户没有做出选择,并且与

选择的选项相关联的值如果她这样做了。这适用于我迄今为止尝试过的所有浏览器(IE6,NN7,NN4,Opera 7)。不过,我是

不确定这是否是标准行为(发回与字段名称相关的最后一个值),而且我一直无法

在网上找到关于这种情况的任何事情(也许我没有找到正确的地方所以指向一些来源

的信息将是一个很好的答案)。

我认为在一个表单中复制字段名称可能是一个坏主意(如果它们具有不同的类型'b $ b''类型',则更是如此)但是另一种方式这个问题(添加一个隐藏的字段,其中包含页面中包含的问题列表

然后修改相关的CGI以明确扫描这些问题)将需要在整个项目中进行大手术
我们现在买不起的东西...... :)


非常感谢,拜托,*做*让我知道如果这个问题不在话题,我不想让你的生活变得悲惨。

Andres。


- -

解决方案




Andres Eduardo Hernando写道:

当< form>中的多个字段附加相同的名称时,标准行为(如果有)是什么?




检查
http ://www.w3.org/TR/html4/interact/...html#h-17.13.2

也许
http://www.w3.org/TR/html4/interact/forms.html #radio

如果你有几个< input type =" radio"名称= QUOT; radioName" ...>在一个

形式中,这些形成一组互斥的按钮,其中只有一个可以一次检查
,因此只有一个可以是

成功并提交。对于其他控件,如果你有几个与

相同的名称,那么对于每个成功控件,name = value对是

提交。

-


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


Andres Eduardo Hernando< he ****** @ ls02.fas.harvard.edu>在消息新闻中写道:< bu ********** @ news.fas.harvard.edu> ...

什么是标准行为(如果有的话)名称附加到< form>中的多个字段?


看来所有成功的控件都是以

的形式数据集提交的,即使它们共享相同的名称。

一个例子(与我正在研究的问题非常相似)将是
(这是一个没有默认选择选项的标准广播组)
[snip]


RFC 1866说:


"在任何时候,都会检查集合中的一个单选按钮。

如果没有< INPUT>一组单选按钮的元素指定

`CHECKED'',然后用户代理必须检查初始设置的第一个单选按钮




因此,应选择一个单选按钮,但大多数用户代理

不符合此要求。

如果用户只点击 ;提交"我们不会为该领域获得任何价值Q1,
什么是正确的行为,因为没有选择的选项。




虽然应该根据RFC 1866 ...


你的技术可能会起作用,虽然它依赖于

非标准行为。


---萨法拉(Stephen Morley)---
http://www.safalra.com/hypertext


us_S@safalra.com (Safalra)写道:

Andres Eduardo Hernando< he ****** @ ls02.fas.harvard.edu> ;在消息新闻中写道:< bu ********** @ news.fas.harvard.edu> ...

什么是标准行为(如果有的话)名称附加到< form>中的多个字段?
似乎所有成功的控件都要在表单数据集中提交,即使它们共享相同的名称。

一个例子(与我正在研究的问题非常相似)将是
(这是一个没有默认选择选项的标准广播组) /> [snip]



RFC 1866说:

"在任何时候,都会检查一组中的一个单选按钮。
如果没有< INPUT>一组单选按钮的元素指定
`CHECKED'',然后用户代理必须检查初始设置的第一个单选按钮。

所以一个单选按钮应该被选中,尽管大多数用户代理都不尊重这个要求。

如果用户只点击提交。我们不会为该领域获得任何价值Q1,
什么是正确的行为,因为没有选择的选项。



虽然应该有根据RFC 1866 ...




这是HTML 2的规范,已经被HTML 4取代了四年

前状态,如果共享

相同控制名称的集合中没有单选按钮最初是开启,则用户代理行为用于选择

哪个控制最初是开启。上"未定义。例如,IE 6

没有选择任何选项,如果它们都没有CHECKED

属性。

你的技术会可能有用,虽然它依赖于非标准行为。

---萨法拉(Stephen Morley)---
http://www.safalra.com/hypertext



-

Harlan Messinger

从我的电子邮件地址中删除第一个点。

Veuillez?ter le premier point de mon adresse de courriel。


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.

--

解决方案



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/


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


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.


这篇关于表单中的重复字段名称...标准行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆