Javascript Image objects not loaded

G

guywmustang

So, basically this is the problem.

I have this...
<div id="mainframe">
<img src="image.jpg" id="image">
</div>

Then when I try to in a function say...

function checkImage()
{
var image = document.getElementById("image");
var height = image.height;
}

--------------
Many times the image height will not be defined.

I recently changed the past so it uses AJAX to change the <img src...
stuff to return new data for that inner HTML block..

Still the image will not have properties.
Now, this is a problem in IE/FF, but not in opera.

Any ideas on how to make sure the image is loaded so its height/width
properties are available... either by swapping the image.src or by
using ajax to swap out the div innerHTML??
 
R

Randy Webb

guywmustang said the following on 9/2/2006 3:06 AM:
So, basically this is the problem.

I have this...
<div id="mainframe">
<img src="image.jpg" id="image">
</div>

Then when I try to in a function say...

function checkImage()
{
var image = document.getElementById("image");
var height = image.height;
}

It will be defined, it just won't be defined when you try to call it.
I recently changed the past so it uses AJAX to change the <img src...
stuff to return new data for that inner HTML block..
Still the image will not have properties.
Now, this is a problem in IE/FF, but not in opera.

Any ideas on how to make sure the image is loaded so its height/width
properties are available... either by swapping the image.src or by
using ajax to swap out the div innerHTML??

Use the onload of the img to make sure it is loaded.
 
G

guywmustang

The onload is exactly what I needed! Thanks!

I don't know all the javascript events and such, so this is a good
forum to turn to thanks to the people here!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top