如果多个文本字段具有相同名称会发生​​什么? [英] What happens if several text fields have the same name?

查看:63
本文介绍了如果多个文本字段具有相同名称会发生​​什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像,我知道如果几个复选框具有相同的名称,我可以获得

那些在提交后检查了request.form(" name")和

可能会进行拆分(request.form(" name"),",")循环使用它们。

我尝试使用textfields(输入类型=文本) ,但是没有
似乎工作相同。

他们的行为有不同吗?

解决方案



wo ****** @ yahoo.com 写道:

就像,我知道如果几个复选框具有相同的名称,我可以获得在提交后使用request.form(" name")检查的那些复选框。 ;)和
可能会进行拆分(request.form(" name"),",")来循环使用它们。
我尝试使用textfields(输入类型=文本) ,但似乎没有相同的工作。
他们的行为有什么不同吗?



提交表单数据时,在

服务器上提交了name = value对,你无法从提交的数据中判断它是否来自

输入类型=" text"或输入type =" checkbox"控制。

至于处理服务器上提交的表单数据依赖于服务器上使用的框架/语言,如果你使用ASP / VBScript则

你可以为每个循环使用a例如


For Request.Form中的每个值(" inputName")

Response.Write Value &安培; "< br>"

下一页


如果您使用的不是ASP,请在适当的组中询问

您正在使用的服务器端框架/语言。对于进一步的ASP问题

你可以使用nsnews.microsoft.com上的ASP组。

-


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


2005年5月24日09:00:50 -0700,
wo **** **@yahoo.com 发布:

就像,我知道如果几个复选框具有相同的名称,我可以获得提交后检查的那些复选框使用request.form(" name")和
可能会进行拆分(request.form(" name"),",")来循环使用它们。
我尝试了同样的方法。 textfields(输入类型=文本)的东西,但似乎没有相同的工作。
他们的行为有什么不同吗?




这听起来像是一个JavaScript问题,而不是HTML(你将如何使用

形式),但你并没有真正说出你在做什么怎么样,听起来很像你可能会错误地使用表格。


对于像收音机或选择表格元素这样的东西,你在哪里使用

任意一个特定答案的多项选择(是否允许选择多个

答案 - 复选框,或只有一个答案中的所有

选项 - 单选按钮),所有*关联的*输入元素都必须使用相同的名称。相反,任何不相关的输入元素都必须使用不同的名称。


例如


< fieldset>

< legend>性别< / legend>

< label>< input type =" radio"名称= QUOT;性"值= QUOT;雌性">女性< / label>< br>

< label>< input type =" radio"名称= QUOT;性"值= QUOT;雄">男性< / label>< br>

< label>< input type =" radio"名称= QUOT;性"值= QUOT;其他">其他< / label>

< / fieldset>


< fieldset>

< legend>喜欢这些宠物< / legend>

< label>< input type ="复选框"名称= QUOT;宠物"值= QUOT;猫">猫< / label>< br>

< label>< input type ="复选框"名称= QUOT;宠物"值= QUOT;狗">狗< / label>< br>

< label>< input type =" checkbox"名称= QUOT;宠物"值= QUOT;鱼"> fish< / label>

< / fieldset>


但是,对于像文本输入元素这样的东西,它们都是个体的,

独立的数据输入小工具,每个小工具都必须使用自己的名字。


例如


< fieldset>

< legend>您的姓名< / legend>

< label>名字:< input type =" text" name =" firstname">< / label>< br>

< label>姓:< input type =" text" name =" lastname">< / label>

< / fieldset>


-

如果你坚持通过电子邮件发送给我,使用回复地址(这是真实的,但暂时是
)。但请回复小组,就像你应该的那样。


这条消息是在没有病毒的情况下发送的,请自行删除一些文件。

< br>

Tim写道:

2005年5月24日09:00:50 -0700,
wo ****** @ yahoo.com 发布:

就像,我知道如果几个复选框具有相同的名称,我可以获取在使用request.form(" name")提交后检查的那些,并且
可以执行拆分(request.form(" name"),",")to循环使用它们。
我尝试使用textfields(输入类型=文本),但似乎没有相同的工作。
他们的行为是否有所不同?



这听起来像是一个JavaScript问题,而不是HTML(你打算如何使用
表格),但你并没有真正说出你在做什么以及如何做,它听起来像你可能正在使用表格incorr对于像收音机或选择表单元素之类的东西,你在任何一个特定答案中使用
多种选择(是否允许选择中的多个
答案) - 复选框,或者只有一个答案 - 选项 - 单选按钮),所有*相关*输入元素必须使用相同的名称。相反,任何不相关的输入元素都必须使用不同的名称。

例如

< fieldset>
< legend>性别< / legend>
< label>< input type =" radio"名称= QUOT;性"值= QUOT;雌性">女性< / label>< br>
< label>< input type =" radio"名称= QUOT;性"值= QUOT;雄">男性< / label>< br>
< label>< input type =" radio"名称= QUOT;性"值= QUOT;其他">其他< / label>
< / fieldset>
< fieldset>
< legend>喜欢这些宠物< / legend>
< label>< ; input type =" checkbox"名称= QUOT;宠物"值= QUOT;猫">猫< / label>< br>
< label>< input type ="复选框"名称= QUOT;宠物"值= QUOT;狗">狗< / label>< br>
< label>< input type ="复选框"名称= QUOT;宠物"值= QUOT;鱼"> fish< / label>
< / fieldset>

但是,对于像文本输入元素这样的东西,它们都是独立的,独立的数据输入小工具,每个人都必须使用自己的名字。




参考?我不认为他们必须这样做,而且效果很好。在ASP中,

你得到一个值数组,无论是SELECT选项,

复选框还是文本字段。


Like, I know if several checkboxes have the same name, I can get the
ones that were checked after submit with a request.form("name") and
maybe do a split(request.form("name"),",") to cycle through them.
I tried the same thing with textfields (input type=text), but doesn''t
seem to work the same.
Do they behave differently?

解决方案



wo******@yahoo.com wrote:

Like, I know if several checkboxes have the same name, I can get the
ones that were checked after submit with a request.form("name") and
maybe do a split(request.form("name"),",") to cycle through them.
I tried the same thing with textfields (input type=text), but doesn''t
seem to work the same.
Do they behave differently?



When form data is submitted name=value pairs are submitted so on the
server you can''t tell from the submitted data whether it comes from
input type="text" or input type="checkbox" controls.
As for processing the submitted form data on the server that depends on
the framework/language used on the server, if you use ASP/VBScript then
you can use a for each loop e.g.

For Each Value In Request.Form("inputName")
Response.Write Value & "<br>"
Next

If it is not ASP you are using then ask in an appropriate group on the
server side framework/language you are using. For further ASP questions
you could use the ASP groups on nsnews.microsoft.com.
--

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


On 24 May 2005 09:00:50 -0700,
wo******@yahoo.com posted:

Like, I know if several checkboxes have the same name, I can get the
ones that were checked after submit with a request.form("name") and
maybe do a split(request.form("name"),",") to cycle through them.
I tried the same thing with textfields (input type=text), but doesn''t
seem to work the same.
Do they behave differently?



This sounds like a JavaScript issue, not HTML (how you''re going about using
forms), but you don''t really say what you''re doing and how, and it sounds
like you might be using forms incorrectly.

For things like radio or select form elements, where you''re using
multiple-choices for any one particular answer (whether allowing multiple
answers out of the choices - checkboxes, or only one answer out of all of
the choices - radio buttons), all the *associated* input elements have to
use the same name. And conversely, any disassociated input elements must
use different names.

e.g.

<fieldset>
<legend>Gender</legend>
<label><input type="radio" name="sex" value="female"> female</label><br>
<label><input type="radio" name="sex" value="male"> male</label><br>
<label><input type="radio" name="sex" value="other"> other</label>
</fieldset>

<fieldset>
<legend>Likes these pets</legend>
<label><input type="checkbox" name="pets" value="cats"> cats</label><br>
<label><input type="checkbox" name="pets" value="dogs"> dogs</label><br>
<label><input type="checkbox" name="pets" value="fish"> fish</label>
</fieldset>

But, for things like text input elements, they''re all individual,
stand-alone, data entry gadgets, and each must use their own names.

e.g.

<fieldset>
<legend>Your names</legend>
<label>First name: <input type="text" name="firstname"></label><br>
<label>Surname: <input type="text" name="lastname"></label>
</fieldset>

--
If you insist on e-mailing me, use the reply-to address (it''s real but
temporary). But please reply to the group, like you''re supposed to.

This message was sent without a virus, please delete some files yourself.


Tim wrote:

On 24 May 2005 09:00:50 -0700,
wo******@yahoo.com posted:

Like, I know if several checkboxes have the same name, I can get the
ones that were checked after submit with a request.form("name") and
maybe do a split(request.form("name"),",") to cycle through them.
I tried the same thing with textfields (input type=text), but doesn''t
seem to work the same.
Do they behave differently?


This sounds like a JavaScript issue, not HTML (how you''re going about using
forms), but you don''t really say what you''re doing and how, and it sounds
like you might be using forms incorrectly.

For things like radio or select form elements, where you''re using
multiple-choices for any one particular answer (whether allowing multiple
answers out of the choices - checkboxes, or only one answer out of all of
the choices - radio buttons), all the *associated* input elements have to
use the same name. And conversely, any disassociated input elements must
use different names.

e.g.

<fieldset>
<legend>Gender</legend>
<label><input type="radio" name="sex" value="female"> female</label><br>
<label><input type="radio" name="sex" value="male"> male</label><br>
<label><input type="radio" name="sex" value="other"> other</label>
</fieldset>

<fieldset>
<legend>Likes these pets</legend>
<label><input type="checkbox" name="pets" value="cats"> cats</label><br>
<label><input type="checkbox" name="pets" value="dogs"> dogs</label><br>
<label><input type="checkbox" name="pets" value="fish"> fish</label>
</fieldset>

But, for things like text input elements, they''re all individual,
stand-alone, data entry gadgets, and each must use their own names.



Reference? I don''t think they have to, and it works just fine. In ASP,
you get an array of values, whether it''s with SELECT options,
checkboxes, or text fields.


这篇关于如果多个文本字段具有相同名称会发生​​什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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