0

I'm working with some javascript (about 12,000 lines of it) and there is a few instances of this

if (!chkLoad.checked) {

But when I do a search for chkLoad I cannot find it declared of assigned anywhere. I even searched multiple files from the root of the project and even though it finds 50 instances of chkLoad it does not find anything like

var chkLoad = document.getElementById('chkLoad');

When I debug the site in Firebug, when I break on one of the conditionals, it does show that chkLoad is in fact the element with ID of chkLoad, but no where in the code shows the assignment of chkLoad.

What might I be missing with my search to find where chkLoad is defined and then assigned?

Onyxdragun
  • 117
  • 1
  • 3
  • 13
  • Is it one single 12000 line file? Look in your HTML, maybe it's declared there. – elclanrs Nov 20 '13 at 22:29
  • Only html is - That wouldnt assign it the js variable of chkLoad though? – Onyxdragun Nov 20 '13 at 22:31
  • 2
    Some browsers, I think, *do* automatically create globals based on the `id` of elements, as mentioned here: http://stackoverflow.com/questions/7114956/automatically-created-variables-from-ids-in-js and http://stackoverflow.com/questions/5515659/javascript-variable-corresponds-to-dom-element-with-the-same-id – David Thomas Nov 20 '13 at 22:35

1 Answers1

1

In Javascript, you can refer to an HTML element by it's ID.

HTML:

<input type="checkbox" id="chkLoad">

JS:

alert(chkLoad.checked)

Here is the fiddle: http://jsfiddle.net/qC76e/

Apologies that you've inherited 12,000 lines of JS.

mcranston18
  • 4,680
  • 3
  • 36
  • 37