473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Images and the onError event

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.

Apr 5 '07 #1
1 1778
"Jake G" <jg******@dps.state.oh.uswrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
>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
Apr 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Fabian | last post by:
var preload1 = new Image(); preload1.src = "/pic/yay.gif"; var preload2 = new Image(); preload2.src = "/pic/nay.gif"; The above is meant to preload image files, yes? Problem is, it doesnt seem...
1
by: Nick | last post by:
How to change the pic to a "show error" image when loading images failed - for example, no image file exists? I tried to add the following statement in the onload event function: if...
15
by: Jake | last post by:
Not sure if this can be done with javascript but I would like to find a way to detect if an image is missing and replace it with a default image instead of the dreaded RED X showing up. So - Is...
2
by: Tee | last post by:
what's the differences between "Overrides Sub OnError" and "Sub Page_Error" ?
0
by: JR | last post by:
I am opening a html page using showModalDialog. To the page's onError event, i am attaching custom event handler. When ever any exception occures, onError event is firing 2 times. I found the same...
4
by: shapper | last post by:
Hello, I am working in Asp.Net 2.0 web sites and I need to preload some images in my master pages and in the pages that use those master pages. Could someone tell me how to do this? Thanks,...
2
by: JD | last post by:
Hello, I have webcams, and I want to display the images (jpg) from the cameras on a webpage, refreshed continuously. For a smooth transition I found a script that utilises double buffering....
1
by: mlikesit | last post by:
I am trying to get the following code to pre-load some images before re-dirrecting the user. The problem is that the onError event gets called for all of the images immediately. I've tripple...
4
by: josh | last post by:
Hi if I try to attach onerror event via addEventListener window.addEventListener("error", myError, false) it does not work as it pass to myError only the event object but not the three...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.