Sanding our assholes with 150 grit.

External javascript not "aware" of the DOM of parent document?

OK so I've got a document with an included .js file (<script type="text/javascript" src="foo.js" />)

I know that my functions are being called from the parent document, because if I put an alert as the first line of any given function, I get the little box.

BUT, if I try to do anything that access the elements in the parent document:

alert(document.getElementByID('bar').value);

Nothing happens. Nada.

Any ideas?

PS - the parent document happens to be XUL but I think that what applies to XHTML should also apply here since mozilla uses the same rendering code on the backend, more or less.
Permalink Mark Warner 
January 11th, 2006
Have you looked at the JavaScript console?
Permalink Dennis Forbes 
January 11th, 2006
I don't even know how to access the javascript console. :-)
Permalink Mark Warner 
January 11th, 2006
Oh hey look at that.
Permalink Mark Warner 
January 11th, 2006
In what way is the parent document XUL?
Permalink Simon Lucy 
January 11th, 2006
Simon? The <script> element lives in a XUL file, not an XHTML file. The namespace is XUL's, not XHTML's.

Dennis -

The console says document.getElementByID() is not a function.

WTF?
Permalink Mark Warner 
January 11th, 2006
Isn't it getElementById (lower-case ending d)?
Permalink Dennis Forbes 
January 11th, 2006
Yes, yes it is.

Good lord that was stupid of me.
Permalink Mark Warner 
January 11th, 2006
In my defense, it should be ID.

:-)
Permalink Mark Warner 
January 11th, 2006
I agree. Acronyms in camelcase are often a mess, and different vendors follow different "standards".
Permalink Dennis Forbes 
January 11th, 2006
"In my defense, it should be ID."

IDentifier ??
Permalink Almost H. Anonymous 
January 11th, 2006
Almost -

Whether or not it's logical form, "ID" has become the defacto acronym for Identification. Get over it, you smelly pedant.
Permalink Mark Warner 
January 11th, 2006
Anyway you're ONLY being pedantic about this because it's ME. :-)
Permalink Mark Warner 
January 11th, 2006
Certainly not.. I'm pendantic with everyone, just check out my posts on the main forum.
Permalink Almost H. Anonymous 
January 11th, 2006
I've made that exact same mistake several times. Writing javascript is painful. The Venkman debugger helps a bit. Have a look if you want.

http://www.mozilla.org/projects/venkman/
Permalink sixtyten 
January 11th, 2006
Does your IDE not have auto-correct for munged case? I try and avoid JS when possible and just use a vanilla editor when I do have to play with it, but I swear I used to use some editor or other that would fix stupid things like that...
Permalink Mat Hall 
January 11th, 2006
I've never met an IDE I didn't hate.
Permalink Mark Warner 
January 11th, 2006
"Good lord that was stupid of me."

"We're only human
Of flesh and blood we're made..."
Permalink Human League 
January 12th, 2006

This topic was orginally posted to the off-topic forum of the
Joel on Software discussion board.

Other topics: January, 2006 Other topics: January, 2006 Recent topics Recent topics