HighDots Forums  

Javascript Image objects not loaded

Javascript JavaScript language (comp.lang.javascript)


Discuss Javascript Image objects not loaded in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
guywmustang
 
Posts: n/a

Default Javascript Image objects not loaded - 09-02-2006 , 03: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;
}

--------------
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??


Reply With Quote
  #2  
Old   
Randy Webb
 
Posts: n/a

Default Re: Javascript Image objects not loaded - 09-02-2006 , 12:50 PM






guywmustang said the following on 9/2/2006 3:06 AM:
Quote:
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.
It will be defined, it just won't be defined when you try to call it.

Quote:
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #3  
Old   
guywmustang
 
Posts: n/a

Default Re: Javascript Image objects not loaded - 09-03-2006 , 08:45 PM



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!


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.