[thelist] JS Help...again

Aylard JA (James) jaylard at equilon.com
Tue Feb 13 17:39:16 CST 2001


> There's this one elementary concept that just doesn't make sense
> though...over and over again, I try to construct references to objects
> aren't recognized. That null or undefined error is ready to have me throw
> brick through my monitor.

	First, spare your poor monitor! :) When are you calling these
scripts? Are they located within a function? Or outside of a function (and
thus parsed as the browser encounters them)? If they are outside of a
function, most likely the objects that you are referencing have not yet been
parsed by the browser, and thus do not yet exist. (In fact, even if your
scripts are inside of a function, it is possible to call them too early --
such as from an onmouseover of a link at the top of your page calling an
object at the bottom of the page). If that's the case, you need to run these
scripts either within a function that is called by the document's onload
event, or by putting the scripts at the bottom of your page, beneath the
point where the objects are created (although that can get dicey, too -- it
	When you are creating an array and you want to reference objects
that may or may not yet be recognized by the browser, another approach is to
create them as simple strings and later bring them to life, like so:

var AllProperties = new Array() ;
AllProperties[0] = "tavares_bay_home" ;
AllProperties[1] = "tropical_hideaway" ;
AllProperties[2] = "rays_hanawi" ;

and later, in script located within a function, you can do thus and so:

for (i = 0 ; i < AllProperties.length ; i++) {
   var myFormElement = parent.topFrame.document.form1[AllProperties[i]] ;
   alert(myFormElement.name) ; // or something more productive...

	And since you appear to be working with frames, you need to make
sure that the frame in which the referenced objects are located is also
loaded, so you'd probably want to call your function from the frameset's
onload event, or from the onload of the frame that contains the objects. The
other point, of course, is that the objects actually have to be there --
misspellings or messed up capitalization can cause severe headaches.

James Aylard

More information about the thelist mailing list