469,282 Members | 1,701 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

How to get Variable value not Variable name.

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?
Jul 20 '05 #1
11 29604
In article <18**************************@posting.google.com >,
la***********@students.uwlax.edu says...
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. 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.
Jul 20 '05 #2
YD
Pete Mahoney wrote:
[...]
Now when I pass the onClick=""checkAll(this.form,name) part I go to:


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.
Jul 20 '05 #3
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!
Jul 20 '05 #4
"Pete Mahoney" <la***********@students.uwlax.edu> wrote in message
news:18**************************@posting.google.c om...
<snip>
<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)
form.elements[i].checked = false;
}
</script>

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

"CheckBoxName.checked is null or not declared"

<snip>

No it doesn't. The message states that "form.checkNoxName is null or not
an object" ( or local translation). If you are going to state error
messages it would be a good idea to _read_ the message first.

See:-

< URL: http://www.jibbering.com/faq/#FAQ4_39 >

And read the linked article (sq_brackets.html).

Richard.
Jul 20 '05 #5
This still does not work. I get an error that says:

Error, 'Checked' is null or not an object

Checkboxes in HTML have a checked option, why does it think this is an
object and not a method? Please help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #6
"Dan Brussee" <db******@NOTbetterwaycomputing.com> wrote in message
news:MP************************@news-server.nc.rr.com...
<snip>
... . Make sure there is a space between the form
object and the first square bracket.


Why?

Richard.
Jul 20 '05 #7
Hi Richard,

Actually the error message said exactally that. I have tryed the []
thing and it still gives me that same error. Any idea why this is
happening?

I tryed this (myform [CheckName].checked)

I am 100% sure I have a checkbox with that name, and wonder why I keep
getting this error.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #8
In article <bf*******************@news.demon.co.uk>,
Ri*****@litotes.demon.co.uk says...
"Dan Brussee" <db******@NOTbetterwaycomputing.com> wrote in message
news:MP************************@news-server.nc.rr.com...
<snip>
... . Make sure there is a space between the form
object and the first square bracket.


Why?


I must admit I do not have documentation to show why I say that, but I
do know that I always put the space there and it always works. I have
seen code that did not work without it, but I cannot give you the
reasons why it did not. I suppose I should find this out some day :)
--

Remove NOT from email address to reply. AntiSpam in action.
Jul 20 '05 #9
"Dan Brussee" <db******@NOTbetterwaycomputing.com> wrote in message
news:MP************************@news-server.nc.rr.com...
<snip>
... . Make sure there is a space between the form
object and the first square bracket.


Why?


I must admit I do not have documentation to show why I
say that, but I do know that I always put the space there
and it always works. I have seen code that did not work
without it, but I cannot give you the reasons why it did
not. I suppose I should find this out some day :)


JavaScript is very tolerant of white space but I think that if you have
seen code that did not work without the space then the space or
otherwise was not the cause. I never include spaces in square bracket
property accessors (I think that it would make the code obscure) and I
have never had a problem doing so.

Richard.
Jul 20 '05 #10
"Peter Landerud" <la***********@students.uwlax.edu> wrote in message
news:3f*********************@news.frii.net...
Actually the error message said exactally that. I
have tryed the [] thing and it still gives me that
same error. Any idea why this is happening?

I tryed this (myform [CheckName].checked)

I am 100% sure I have a checkbox with that name, and
wonder why I keep getting this error.


There is nothing in your script that treats - CheckBoxName.checked - as
if it was an object so your browser should not even be attempting to
resolve it as an object reference.

However, I did notice that you have more opening braces ( - { - ) than
closing so it might be that you are using IE to test and suffering an
unusual side effect of its excessive error correcting behaviour.
Generally Gecko browsers (Mozilla, etc.) and Opera 7 give much better
error reports and do not even attempt to second guess erroneous
JavaScript.

Richard.

Jul 20 '05 #11
Incidentally, the current HTML specifications forbid the strings in name
and ID attributes from starting with a number so your "194_solaris" name
attribute is invalid. While most browsers don't seem to care about this
it is not realistic to expect invalid HTML to result in a consistent or
usable DOM or to expect all browsers to react in the same way to invalid
code.

Richard.
Jul 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Geoff Winsor | last post: by
9 posts views Thread by Max | last post: by
166 posts views Thread by Graham | last post: by
23 posts views Thread by Russ Chinoy | last post: by
3 posts views Thread by rls03 | last post: by
2 posts views Thread by Kevin | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.