Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Error message on a Javascript variable definition

Posted on 2007-10-09
6
Medium Priority
?
433 Views
Last Modified: 2010-08-05
Hello,

Hopefully an easy one. I am using the solution provided in: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_22103340.html

and am getting an error when the page loads stating 'thebox' is undefined.

thebox is the variable in the javascript code. The page works fine, but the little Error on Page is nagging me. How do I define the variable and not screw everything else up. I tried adding Var thebox; within the script tages but then it errors on the var checked boxes saying it is null or without a value.

Thanks for a quick response!
0
Comment
Question by:webkiwi1
  • 3
  • 2
6 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 1200 total points
ID: 20043419
The var thebox is a parameter variable passed to the function toggleBoxes(thebox). But it is passed only if you call the function with the predefined reference: "this"
Like here:
<td align="center"><input type="checkbox" name="Chk" onclick="return toggleBoxes(this)" value="<%=C1%>"></td>

0
 

Author Comment

by:webkiwi1
ID: 20043457
OK, I am doing that in an include file:
<td class="style4" align="center"><input type="checkbox" name="Chk" onclick="return toggleBoxes(this)" value="<%=fPin%>"></td>

How do I get rid of the undefined error?
0
 
LVL 9

Assisted Solution

by:CCongdon
CCongdon earned 300 total points
ID: 20043502
One suggestion is to pass your code through http://www.jslint.com

It is very strict at times, but it has helped me a LOT at pinning down pesky errors.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:webkiwi1
ID: 20043552
checked and tried jslint but:

JavaScript's biggest problem is its dependence on global variables, particularly on implied global variables. If a variable is not explicitly declared (usually with the var statement), then Javascript assumes that the variable was global. This can mask misspelled names and other problems.

JSLint expects that all variables and functions are declared before they are used or invoked. This allows it to detect implied global variables. It is also good practice because it makes programs easier to read.

This is the crux of my question, how/where do I declare the variable 'thebox'?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 20052251
The variable thebox has NOT to be defined before. It would not be an error but it is not used as var. It is a function PARAMETER that needs to be passed to the function.
The parameter is passed to function call and it is a reference to an element on the document. If you do not pass a valid reference, then is the parameter thebox not defined.

And the call parameter needs to be passed in the onclick event handler. Can we see your page live on internet? Or can you post the html source of the page as seen in the browser?


0
 

Author Comment

by:webkiwi1
ID: 20371493
Moved on to a different project now and do not have time to work through this one. The page loads and works etc just shows the javascript error!

Points awarded for the help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question