传递多个复选框变量w /相同的cb名称? [英] passing multiple checkbox variables w/same cb name ?

查看:57
本文介绍了传递多个复选框变量w /相同的cb名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在alt.comp.lang.coldfusion上发布了这个,但主要是一个

javascript问题:


我有一个CF查询它返回几行记录。我想

在返回的查询的每条记录上都有一个复选框,这将允许用户在选中时选择要打印的记录。

由于复选框是在CF中生成的,因此它们都具有相同的

名称。在a.c.l.c的同事的帮助下。会员,我们有一个脚本

到一个点,它将定义是否检查1个盒子,只有

当有超过1个时,我收到错误:''f.length为null或

不是对象''。


这里是脚本,就像现在一样。非常感谢任何帮助:

< script language =" JavaScript">

function win(){

var s ='' '';

f = document.boxs;

for(var i = 0; i< f.length; i ++){

if (f.elements [i] .name ==''printprop''&& f.elements [i] .checked){

if(s.length!= 0)s + = '','';

s + = f.elements [i] .value;

}

} window.open(" openprintR .cfm?ID =" +

s,""," height = 600,width = 600,left = 0,top = 0")

}

< / script>


< body>

< a href =" javascript :win()">打印报告< / a>

< cfoutput query =" myquery">

< form名称= QUOT; boxs"行动= QUOT;的JavaScript的 的:赢()" method =" post">打印此

属性& nbsp;< input type ="复选框" name =" printprop"

value =#ID#>< / form>

< / cfoutput>

史蒂夫。

I''ve posted this on alt.comp.lang.coldfusion, but is predominantly a
javascript problem:

I have a CF query which returns several rows of records. I wanted to
have a checkbox on each record of that returned query which would
allow the user to select which record to print if checked.

As the checkboxes are generated within the CF, they all have tha same
name. With the help of a fellow a.c.l.c. member, we''ve got the script
to a point where it will define whether 1 box is checked or not, only
when there are more than 1, I receive the error: ''f.length is null or
not an object''.

Here''s the script as it is now. Any help greatly appreciated:
<script language="JavaScript">
function win(){
var s = '''';
f = document.boxs;
for (var i=0;i < f.length;i++){
if (f.elements[i].name == ''printprop'' && f.elements[i].checked){
if (s.length != 0) s += '','';
s += f.elements[i].value;
}
} window.open("openprintR.cfm?ID=" +
s,"","height=600,width=600,left=0,top=0")
}
</script>

<body>
<a href="javascript:win()">print report</a>

<cfoutput query="myquery">
<form name="boxs" action="javascript:win()" method="post">print this
property&nbsp;<input type="checkbox" name="printprop"
value=#ID#></form>
</cfoutput>
Steve.

推荐答案

文章< f7 ************************* *@posting.google.com>,
vi******@btopenworld.com 开明我们......

In article <f7**************************@posting.google.com >,
vi******@btopenworld.com enlightened us with...


这是现在的脚本。任何帮助非常感谢:

Here''s the script as it is now. Any help greatly appreciated:




假设1:你想要一个字符串s使用选中的

复选框的值,用逗号分隔。

假设2:所有复选框都命名为printprop。


请注意,这是测试脚本,因此值是硬编码的,并且链接集

要提醒。根据需要更改。


< html>

< head>

< title>新文档< / title>

< script language =" javascript" type =" text / javascript">

function win()

{

var s ='''';

f = document.forms [" boxs"]。elements [" printprop"];

if(f.length)

{

for(var i = 0; i< f.length; i ++)

{

if(f [i] .checked)

{

if(s.length!= 0)s + ='','';

s + = f [i] .value;

}

}

}

否则如果(f)

{

s + = f.value;

}

alert(s);

}

< / script>

< / head>


< body>

< a href =" #"的onClick = QUOT;赢();返回false;">打印报告< / a>


< form name =" boxs"行动= QUOT;" method =" get">

property 1:< input type =" checkbox"命名= QUOT; printprop" value ='''''>< br>

property 2:< input type =" checkbox"命名= QUOT; printprop" value ='''''>< br>

property 3:< input type =" checkbox"命名= QUOT; printprop" value =''3''>< br>

< / form>

< / body>

< / html>


-

-

~kaeli~

你觉得你被困在了债务,如果你不能让步。
http://www.ipwebdesign。 net / wildAtHeart
http://www.ipwebdesign.net/kaelisSpace



Assumption 1: you want a string "s" with the values of the checked
checkboxes, separated by commas.
Assumption 2: all the checkboxes are named "printprop".

Note that this is the test script, so values are hardcoded and link set
to alert. Change this as needed.

<html>
<head>
<title> New Document </title>
<script language="javascript" type="text/javascript">
function win()
{
var s = '''';
f = document.forms["boxs"].elements["printprop"];
if (f.length)
{
for (var i=0;i < f.length;i++)
{
if (f[i].checked)
{
if (s.length != 0) s += '','';
s += f[i].value;
}
}
}
else if (f)
{
s += f.value;
}
alert(s);
}
</script>
</head>

<body>
<a href="#" onClick="win(); return false;">print report</a>

<form name="boxs" action="" method="get">
property 1:<input type="checkbox" name="printprop" value=''1''><br>
property 2:<input type="checkbox" name="printprop" value=''2''><br>
property 3:<input type="checkbox" name="printprop" value=''3''><br>
</form>
</body>
</html>

--
--
~kaeli~
You feel stuck with your debt if you can''t budge it.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace


Kaeli,


首先关闭 - 感谢您的回复!


好​​的,我尝试了你的测试脚本,它可以正常使用一个复选框,但

我认为问题在于我必须创建

coldfusion输出表中的复选框,因此它们的

数量取决于返回的行数。


当有超过多个行时1现在,我在提交时收到此错误:


''document.forms.boxs.elements.printprop为null或不是对象''

Steve。


* **通过开发人员指南 http://www.developersdex.com 发送***
不要只是参加USENET ......获得奖励!
Kaeli,

first off - thanks for the reply!

OK, I tried your testing script and it works fine with one checkbox, but
I think the problem lies with the fact that I''m having to create the
checkboxes within a coldfusion output table and therefore their
quantities vary dependant upon how many rows are returned.

When there is more than 1 present, I get this error upon submit:

''document.forms.boxs.elements.printprop is null or not an object''
Steve.

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


文章< 40 ********* **************@news.frii.net>,
vi *** ***@btopenworld.com 启发我们...
In article <40***********************@news.frii.net>,
vi******@btopenworld.com enlightened us with...
凯丽,

首先关闭 - 感谢您的回复!
好的,我尝试了你的测试脚本,它可以正常使用一个复选框,但
我认为问题在于我必须在coldfusion输出表中创建
复选框,因此它们的数量取决于返回的行数。

如果存在多于一行,我会在提交时收到此错误:
Kaeli,

first off - thanks for the reply!

OK, I tried your testing script and it works fine with one checkbox, but
I think the problem lies with the fact that I''m having to create the
checkboxes within a coldfusion output table and therefore their
quantities vary dependant upon how many rows are returned.

When there is more than 1 present, I get this error upon submit:




测试脚本适用于倍数 - 因此,错误是

而不是脚本本身。


让我们看看你生成的HTML - 也就是说,查看页面的来源

查看脚本实际使用的html输出。


我不需要整个东西,如果它是巨大的 - 只是表格和

脚本。


如何生成html没关系,无论是CF,JSP还是

ASP。浏览器只看到html。


-

-

~kaeli~

从不用借口搞砸道歉。
http://www.ipwebdesign.net/ wildAtHeart
http://www.ipwebdesign.net/kaelisSpace



The test script works just fine with multiples - therefore, the error is
not the script per se.

Let''s see your generated HTML - that is, view the source of the page to
see the html output the script is actually working with.

I don''t need the whole thing if it''s huge - just the form and the
script.

How the html was generated doesn''t matter a bit, whether by CF, JSP, or
ASP. The browser sees only html.

--
--
~kaeli~
Never mess up an apology with an excuse.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace


这篇关于传递多个复选框变量w /相同的cb名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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