设置表单的隐藏输入类型 [英] Setting the a form's hidden input type
问题描述
我正在尝试更改并将
表单标记上的隐藏输入类型的值传递给基于的cgi处理脚本形式中的复选框值
:
函数CheckBoxes(){
if(document.MyForm.CheckBox1。已检查){
document.MyForm.recipient.value =" 2";
document.MyForm.submit();
} < br $>
}
...
< form name =" MyForm" action =" http://www.mycompany.com/cgi/MailMyForm.pl"
method =" post" onSubmit ="返回CheckBoxes()">
< input type =" hidden"名称= QUOT;接受者QUOT; value =" 1">
< input name =" CheckBox1"类型= QUOT;复选框" value =" yes">
...
< / form>
显然,这是一个简化真实例子的版本。
收件人值1表示1。是一个默认收件人的电子邮件地址
情况下没有选中复选框。如果(在这种情况下)复选框
" CheckBox1"检查,然后收件人应该设置为值
" 2" cgi脚本将识别为不同的电子邮件地址
并相应地处理表单(它只会转到cgi脚本中定义的电子邮件
地址)对于接收者值2)。
任何想法为什么这不起作用?是不是我无法改变
收件人的价值?
感谢任何帮助。
Hi,
I am trying to change and pass the value of a hidden input type on a
form tag to a cgi processing script based on the value of a checkbox
within the form:
function CheckBoxes () {
if (document.MyForm.CheckBox1.checked) {
document.MyForm.recipient.value = "2";
document.MyForm.submit();
}
}
...
<form name="MyForm" action="http://www.mycompany.com/cgi/MailMyForm.pl"
method="post" onSubmit="return CheckBoxes()">
<input type="hidden" name="recipient" value="1">
<input name="CheckBox1" type="checkbox" value="yes">
...
</form>
Obviously, this is a simplified version of the real example.
The "recipient" value of "1" is a default recipient''s e-mail address in
case no checkboxes are selected. If (in this case) the checkbox
"CheckBox1" is checked, then "recipient" should get set to a value of
"2" which the cgi script will recognize as a different e-mail address
and process the form accordingly (it would just go to the e-mail
address defined in the cgi script for a "recipient" value of "2").
Any idea why this won''t work? Is it that I cannot change the value of
"recipient"?
Any help is appreciated.
推荐答案
Jim Tome写道:
Jim Tome wrote:
function CheckBoxes(){
if(document.MyForm.CheckBox1.checked){
document.MyForm.recipient.value =" 2";
document.MyForm.submit();
}
}
..
< form name =" MyForm" action =" http://www.mycompany.com/cgi/MailMyForm.pl"
method =" post" onSubmit =" return CheckBoxes()">
< input name =" CheckBox1"类型= QUOT;复选框" value =" yes">
..
< / form>
function CheckBoxes () {
if (document.MyForm.CheckBox1.checked) {
document.MyForm.recipient.value = "2";
document.MyForm.submit();
}
}
..
<form name="MyForm" action="http://www.mycompany.com/cgi/MailMyForm.pl"
method="post" onSubmit="return CheckBoxes()">
<input name="CheckBox1" type="checkbox" value="yes">
..
</form>
为什么不摆脱这个功能,并使用onclick事件处理程序
代替它的复选框?
< form action =" http://www.mycompany.com/cgi/MailMyForm .pl"
method =" post" >
< input type =" hidden"名称= QUOT;接受者QUOT; value =" 1">
< input name =" CheckBox1"类型= QUOT;复选框" value =" yes"
onclick =''recipient.value = this.checked?" 2":""">
但是你需要确定用户已经启用了javascript。
Mick
Why not get rid of the function, and use the onclick event handler of
the checkbox in its stead?
<form action="http://www.mycompany.com/cgi/MailMyForm.pl"
method="post" >
<input type="hidden" name="recipient" value="1">
<input name="CheckBox1" type="checkbox" value="yes"
onclick=''recipient.value=this.checked?"2":"1"''>
However you need to be certain that the user has javascript enabled.
Mick
2004年5月6日星期四15:19:23 GMT ,Mick White
< mw ****** @ BOGUSrochester.rr.com>写道:
[snip]
On Thu, 06 May 2004 15:19:23 GMT, Mick White
<mw******@BOGUSrochester.rr.com> wrote:
[snip]
< input name =" CheckBox1"类型= QUOT;复选框" value =" yes"
onclick =''recipient.value = this.checked?" 2":" 1"''>
<input name="CheckBox1" type="checkbox" value="yes"
onclick=''recipient.value=this.checked?"2":"1"''>
这在大多数浏览器中都不起作用。请记住,使用ID和名称作为全局标识符是一个Microsoft标准,并不是标准化的,并且
肯定不会在所有情况下都被复制。
onclick =" this.form.elements [''recipient'']。value = this.checked?'''''''''''"
>
可能是最好的功能。
迈克
-
Michael Winter
M.******@blueyonder.co.inva 盖子(替换.invalid ;用.uk回复)
That won''t work in most browsers. Remember that using ids and names as
global identifiers is a Microsoft-ism that isn''t standardised, and
certainly not copied in all cases.
onclick="this.form.elements[''recipient''].value=this.checked?''2'':''1''"
Probably best in a function.
Mike
--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
是的,谢谢你的建议。我的下一个问题是,假设有
三个复选框(可以选择其中的任何一个或全部)。选中
复选框表示该表单的提交副本通过电子邮件发送给
a单独的收件人,具体取决于选中的复选框(因此,在此
简单的例子,表格会通过电子邮件发送给一个,两个或三个人)。
如何测试和处理这个?
>
再次感谢您的帮助?有时候我太靠近这些东西
看到简单的解决方案了!
2004-05-06 10:19:23 -0500,Mick White < MW ****** @ BOGUSrochester.rr.com>说:
Yes, thank for your suggestion. My next question is, suppose there are
three checkboxes (any or all of which can be selected). Checking a
checkbox indicates that a copy of the form''s submission get e-mailed to
a separate recipient depending on the checkbox checked (so, in this
simple example, the form would e-mail to one, two or three people).
How can I test and handle this?
Thanks again for your help ? sometime I get too close to these things
to see the simple solution!
On 2004-05-06 10:19:23 -0500, Mick White <mw******@BOGUSrochester.rr.com> said:
Jim Tome写道:
Jim Tome wrote:
function CheckBoxes(){
if(document.MyForm.CheckBox1.checked){
document.MyForm.recipient.value =" 2";
document.MyForm.submit();
}
}
..
< form name =" MyForm" action =" http://www.mycompany.com/cgi/MailMyForm.pl"
method =" post" onSubmit =" return CheckBoxes()">
< input name =" CheckBox1"类型= QUOT;复选框" value =" yes">
..
< / form>
function CheckBoxes () {
if (document.MyForm.CheckBox1.checked) {
document.MyForm.recipient.value = "2";
document.MyForm.submit();
}
}
..
<form name="MyForm" action="http://www.mycompany.com/cgi/MailMyForm.pl"
method="post" onSubmit="return CheckBoxes()">
<input name="CheckBox1" type="checkbox" value="yes">
..
</form>
为什么不摆脱这个功能,并使用onclick事件处理程序
取而代之的复选框?
< form action =" http://www.mycompany.com/cgi/MailMyForm.pl"
method =" post" ; >
< input type =" hidden"名称= QUOT;接受者QUOT; value =" 1">
< input name =" CheckBox1"类型= QUOT;复选框" value =" yes"
onclick =''recipient.value = this.checked?" 2":" 1"''>
但是你需要确定用户已启用javascript。
Mick
Why not get rid of the function, and use the onclick event handler of
the checkbox in its stead?
<form action="http://www.mycompany.com/cgi/MailMyForm.pl"
method="post" >
<input type="hidden" name="recipient" value="1">
<input name="CheckBox1" type="checkbox" value="yes"
onclick=''recipient.value=this.checked?"2":"1"''>
However you need to be certain that the user has javascript enabled.
Mick
这篇关于设置表单的隐藏输入类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!