473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 29784
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
3
by: Geoff Winsor | last post by:
Hi, I am experiencing a problem with recalling a session variable which stores whether a person is logged in to a "members only" section of a website. This area of the site has been working...
9
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
10
by: Blaxer | last post by:
There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be... function Calculate_Something(ByVal...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
5
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve...
3
by: rls03 | last post by:
I have the following which creates a variable containing a relative path where <xsl:value-of select="."/returns a portion of the filename: <xsl:variable...
2
by: Kevin | last post by:
I am having difficulty updating a variable page-time-stamp in the following snippit. The variable time-stamp is initialized from the attribute time-stamp from the log element. Some of the page...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.