如何获取变量值而不是变量名称。 [英] How to get Variable value not Variable name.

查看:81
本文介绍了如何获取变量值而不是变量名称。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个ASP页面,在那里我创建了很多

不同的复选框。我有一些复选框是Windows

平台,有些是solaris平台。我想在Windows上打开一个控件

复选框将它们全部打开或全部关闭,并且

与solaris相同。


其中一个控件复选框如下所示:


< input type =" checkbox" name =" objRS(" ProductId")& _solaris

value ="" 0"" onClick ="" checkAll(this.form,name);"">


这给了我一个名字如下的复选框:


194_solaris


194是我公司产品的产品ID,而solaris只是

来判断它的窗户是不是Solaris操作系统。现在我知道这是

的名字,这个复选框不是我的问题。


现在当我通过onClick ="" checkAll(这个.form,name)我去的部分:


< SCRIPT LANGUAGE =" JavaScript">

function checkAll(form,CheckBoxName)

var myVar = CheckBoxName

if(form.CheckBoxName.checked == true){< --------问题行

for(i = 0; i< form.elements.length; i ++)

{

if(form.elements [i] .id == myVar)

form.elements [i] .checked = true;

}

} else {

for(i = 0; i< form.elements.length; i ++)

{

if(form.elements [i] .id == myVar)

表格.elements [i] .checked = false;

}

< / script>


现在当我打电话给我时得到一个错误,好像说:


CheckBoxName.checked为null或未声明


我知道很好,CheckBoxName.checked一世未声明,但

CheckBoxName的VALUE是有效名称。我希望名为CheckBoxName的

变量的内容不是名称。我怎么能这样做?

I am currently working on an ASP page where I create a lot of
different check boxes. I have some checkboxes that are Windows
platforms and some that are solaris platforms. I want a control
checkbox over the Windows ones to turn them all on or all off, and the
same with the solaris.

One of the control check boxes looks something like this:

<input type="checkbox" name="objRS("ProductId") & "_solaris"
value=""0"" onClick=""checkAll(this.form,name);"">

This gives me a check box with a name that looks like:

194_solaris

194 is the productID for a product at my company, and solaris is just
to tell if its windows or solaris. Now I know this is the name of
that checkbox this is NOT my problem.

Now when I pass the onClick=""checkAll(this.form,name) part I go to:

<SCRIPT LANGUAGE="JavaScript">
function checkAll(form, CheckBoxName)
var myVar = CheckBoxName
if (form.CheckBoxName.checked == true){ <-------- Problem Line
for (i=0; i<form.elements.length; i++)
{
if (form.elements[i].id == myVar)
form.elements[i].checked = true;
}
}else {
for (i=0; i<form.elements.length; i++)
{
if (form.elements[i].id == myVar)
form.elements[i].checked = false;
}
</script>

Now when I call this I get an error thats says:

"CheckBoxName.checked is null or not declared"

Well I know good and well CheckBoxName.checked is not declared, but
the VALUE of CheckBoxName is a valid name. I want the content of the
variable named CheckBoxName not the name. How can I do this?

推荐答案

在文章< 18 ****************** ********@posting.google.com>,
la * **********@students.uwlax.edu 说...
In article <18**************************@posting.google.com >,
la***********@students.uwlax.edu says...
我目前正在开发一个ASP页面,在那里我创建了很多
不同的复选框。我有一些复选框是Windows
平台,有些是solaris平台。我希望Windows上的控件复选框可以全部打开或全部关闭,而且与solaris相同。

其中一个控件复选框看起来像这个:

< input type ="复选框" name =" objRS(" ProductId")& _solaris
value ="" 0"" onClick ="" checkAll(this.form,name);"">

这给了我一个名称如下的复选框:

194_solaris

194是我公司产品的产品ID,solaris只是告诉它是windows还是solaris。现在我知道这是
的名称,这个复选框不是我的问题。

现在,当我通过onClick ="" checkAll(this.form,name)部分时我会去to:

< SCRIPT LANGUAGE =" JavaScript">
函数checkAll(form,CheckBoxName)
var myVar = CheckBoxName
if(form.CheckBoxName。 checked == true){< --------问题行
for(i = 0; i< form.elements.length; i ++)
{
< snippage />
" CheckBoxName.checked为null或未声明"

我知道很好并且没有声明CheckBoxName.checked,但
CheckBoxName的值是一个有效名称。我希望名为CheckBoxName的变量的内容不是名称。我怎么能这样做?
I am currently working on an ASP page where I create a lot of
different check boxes. I have some checkboxes that are Windows
platforms and some that are solaris platforms. I want a control
checkbox over the Windows ones to turn them all on or all off, and the
same with the solaris.

One of the control check boxes looks something like this:

<input type="checkbox" name="objRS("ProductId") & "_solaris"
value=""0"" onClick=""checkAll(this.form,name);"">

This gives me a check box with a name that looks like:

194_solaris

194 is the productID for a product at my company, and solaris is just
to tell if its windows or solaris. Now I know this is the name of
that checkbox this is NOT my problem.

Now when I pass the onClick=""checkAll(this.form,name) part I go to:

<SCRIPT LANGUAGE="JavaScript">
function checkAll(form, CheckBoxName)
var myVar = CheckBoxName
if (form.CheckBoxName.checked == true){ <-------- Problem Line
for (i=0; i<form.elements.length; i++)
{ <snippage />
"CheckBoxName.checked is null or not declared"

Well I know good and well CheckBoxName.checked is not declared, but
the VALUE of CheckBoxName is a valid name. I want the content of the
variable named CheckBoxName not the name. How can I do this?




a。我会尽量不使用形式这个词。作为变量名称。很容易

与对象类型混淆。但是,如果它工作 - 很好。


if(form [CheckBoxName] .checked == true){


那应该是您。确保表单

对象和第一个方括号之间有空格。

-


从电子邮件中删除NOT地址回复。反垃圾邮件在行动。



a. I would try not to use the word "form" as a variable name. Too easy
to get mixed up with the object type. But, if it works - fine.

if (form [CheckBoxName].checked == true) {

That should do it for you. Make sure there is a space between the form
object and the first square bracket.
--

Remove NOT from email address to reply. AntiSpam in action.


Pete Mahoney写道:
Pete Mahoney wrote:
[...]
现在当我通过onClick ="" ; checkAll(this.form,name)部分我去:
[...]
Now when I pass the onClick=""checkAll(this.form,name) part I go to:




您可以传递对复选框的引用作为JS函数的参数:

onclick =" checkAll(this)"


并修改功能:


function checkAll(checkbox){

var myForm = checkbox.form;

if(checkbox.checked)/ *无需与真实比较

(如果勾选复选框)你的陈述是if(true == true),if(true)就够了!* /

//等等

}


HTH

-

YD



You may pass a reference to the checkbox as argument of the JS function :
onclick="checkAll(this)"

and modify the function that way :

function checkAll(checkbox){
var myForm=checkbox.form;
if(checkbox.checked) /* no need to compare to true
(if checkbox is checked your statement is if(true==true), if(true) is enough! */
//etc.
}

HTH
--
Y.D.


这也行不通。我收到的错误是什么:


错误,''已检查''为空或不是对象


检查是否是任何复选框的一部分是HTML,我不喜欢我不知道这个

是什么意思。请帮助。


***通过开发人员指南 http:// www发送.developersdex.com ***

不要只是参加USENET ......获得奖励!
This also does not work. I get an error what says:

Error, ''checked'' is null or not an object

Check is a part of any checkbox is HTML and I don''t know what this
means. Please help.

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


这篇关于如何获取变量值而不是变量名称。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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