Forum Moderators: open

Message Too Old, No Replies

document.getElementById("image 0 0") has no properties, but it should!

Why dis image no have properteez?

         

LockeZ

4:55 pm on Aug 2, 2007 (gmt 0)

10+ Year Member



I get the following error message when trying to retrieve the width of an image in my document:

Error: document.getElementById("image_0_0") has no properties

Here's my code:


function widthifyImages() {
SetImageMargin("image_0_0", 0, 0);
}


function SetImageMargin(picName, picNumberA, picNumberB){
var myObject=new Object();

GetRowWidth(picName, picNumberA, picNumberB, myObject);

}

function GetRowWidth(picName, picNumberA, picNumberB, myObject) {
var all_image_widths = new Array();
pic = document.getElementById(picName);
all_image_widths[0] = new Array();
all_image_widths[0][0] = document.getElementById("image_0_0").width;
}

document.onLoad = widthifyImages();

And later in the body of the HTML...:


<img src="1013_1.jpg" alt="Canyon Princess" title="Canyon Princess" name="image_0_0" id="image_0_0" class="artist_img_thumbnail" />

This JS was cut to only the relevant part that has to do with the first image. It seems utterly convinced, no matter how I do it, that the image "image_0_0" has no properties. And yet image_0_0 is right there plain as day! Any thoughts?

[edited by: LockeZ at 5:36 pm (utc) on Aug. 2, 2007]

Trace

2:02 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



Just sounds like the js is running before the image is loaded.

Try putting the js at the end of your document instead of at the beginning.

LockeZ

3:24 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



Always the dumbest things I have problems with. I can do the calculus in my head but I fail at addition.

I thought that the line "document.onload = widthifyImages();" would make it not run until the page loaded, but clearly I was mistaken.

Achernar

5:50 pm on Aug 5, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



"document.onload" is not valid.
You should use "window.onload" which is fired avec all images have been loaded (or failed to).