Posted on 16 Sep 1999
by Jeff Howden (Jeff Howden)
Rated 3.89 (Ratings: 0)
- More articles in Code
When naming objects on a page, most commonly images and form elements, NEVER name any object with the same name.
For instance, let's imagine you had a rather simple page like this:
document.USER_INFO.USER_ID is undefined
or a similar error. The browser thinks it's trying to find the value of the image object named USER_ID, which it can't do because image objects do not have a VALUE attribute associated with them.
The same would be true if you were trying to access an image object with the same name as a FORM element that it followed. It can't find the image because it occurs right after a FORM element with the same name. Since .src is not valid for a FORM element, it returns an error.