Error message on a Javascript variable definition

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!
webkiwi1Asked:
Who is Participating?
 
ZvonkoSystems architectCommented:
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
 
webkiwi1Author Commented:
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
 
CCongdonCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
webkiwi1Author Commented:
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
 
ZvonkoSystems architectCommented:
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
 
webkiwi1Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.