Images and the onError event

J

Jake G

I was wondering if anyone could help me with this?

I am dynamically loading an image after a user selects an item in a
list box. If the image is not available I would like to load a nice
error image, rather than the ugly red x that comes up. Any
suggestions? I was hoping to do it with out another function.


document.getElementById('legimg').src = "../Images/LEG/s_" + distnum +
"_small.jpg";
Thanks,
Jake G.
 
L

-Lost

Jake G said:
I was wondering if anyone could help me with this?

I am dynamically loading an image after a user selects an item in a
list box. If the image is not available I would like to load a nice
error image, rather than the ugly red x that comes up. Any
suggestions? I was hoping to do it with out another function.

I am not entirely sure widely implemented it is, but I have seen a consistent use of
onload and onerror with the IMG tag.

For example:

<img src="http://www.google.com/intl/en_ALL/images/logo.gifx" alt="" width="" height=""
onload="alert('loaded');" onerror="this.src =
'http://www.google.com/images/nav_logo.png';" />

If you load that in Internet Explorer, it will not show the images with empty width and
height attributes.

-Lost
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top