473,396 Members | 1,929 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,396 software developers and data experts.

onError problem loading an image

Good afternoon,

I am handing a string as a parameter pImage = "Images/Available.jpg"
If this image is NOT available I would like to load Images/NoImage.jpg.
Unfortunately the following code does NOT work.
obj.write('<p><img src=' + pImage + '
onError="self.src="Images/NoImage.jpg"" border="0"></p>');
Where is my mistake ?
I appreciate any hint.
Best regards
Juergen Heyn, Wilhelmshaven, Germany
Jul 20 '05 #1
4 8919
Ivo
"Jürgen Heyn" <j.****@gmx.de> wrote in message
news:c1*************@ID-94872.news.uni-berlin.de...
Good afternoon,

I am handing a string as a parameter pImage = "Images/Available.jpg"
If this image is NOT available I would like to load Images/NoImage.jpg.
Unfortunately the following code does NOT work.
obj.write('<p><img src=' + pImage + '
onError="self.src="Images/NoImage.jpg"" border="0"></p>');


Try onError="this.src
^^^^^
Jul 20 '05 #2
Ivo
"Ivo" <no@thank.you> wrote
"Jürgen Heyn" <j.****@gmx.de> wrote
I am handing a string as a parameter pImage = "Images/Available.jpg"
If this image is NOT available I would like to load Images/NoImage.jpg.
Unfortunately the following code does NOT work.
obj.write('<p><img src=' + pImage + '
onError="self.src="Images/NoImage.jpg"" border="0"></p>');


Try onError="this.src
^^^^^

That was too quick. You also have a double-quoted string inside a
double-quoted string, which the interpreter won't understand if you don't
escape the innerquotes:
onError="this.src=\"Images/NoImage.jpg\";"
or
onError="this.src='Images/NoImage.jpg';"

untested,
Ivo


Jul 20 '05 #3
Ivo wrote: <40***********************@news.wanadoo.nl>
"Ivo" <no@thank.you> wrote
"Jürgen Heyn" <j.****@gmx.de> wrote <snip>
NOT work. obj.write('<p><img src=' + pImage + '
onError="self.src="Images/NoImage.jpg"" border="0"></p>');


Try onError="this.src
^^^^^

That was too quick. You also have a double-quoted string inside a
double-quoted string, which the interpreter won't understand if you
don't escape the innerquotes:
onError="this.src=\"Images/NoImage.jpg\";"
or
onError="this.src='Images/NoImage.jpg';"


Take another step back any you will observe that the double quoted
string inside the double quoted string is itself inside a single quoted
string of HTML. Escaping the quotes within the onerror handler will work
for the javascript interpreter but will not be enough for the HTML
parser if the inner set of quotes remain double.

obj.write('<p><img src="'+pImage +
'" onError="this.src=\'Images/NoImage.jpg\';" border="0"></p>');

Richard.
Jul 20 '05 #4
Gentlemen,
thank you very much for your response.
Richard's suggestion works perfectly.
Have a nice rest of this sunday.
Best regards
Juergen Heyn, Wilhelmshaven, Germany
Jul 20 '05 #5

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

Similar topics

1
by: bjarthur | last post by:
i have (see below) what i think is a fairly simple algorithm, but yet it doesn't work. given a directory with consecutively numbered jpeg files (1.jpg, 2.jpg, 3.jpg...), it is designed to count...
4
by: Adrian MacNair | last post by:
Hi, I created an image gallery which displays 63 images in a slideshow. The problem is that the show was slow because each image loaded one at a time during the show. No problem right? I just...
2
by: Tee | last post by:
what's the differences between "Overrides Sub OnError" and "Sub Page_Error" ?
3
by: Tobius | last post by:
I want to be able to define a custom onerror event that detects an attempt to call a known function and load a file if it's not already loaded and re-call the function. The only problem is that any...
0
by: speedcoder | last post by:
hi all, i'm stumped. my applet used to load images over the network. (it was actually designed by someone else.) yes, the applet used to load each image file independently over the network and...
5
by: Pete Verdon | last post by:
I'm working on a fairly sizeable javascript application. I recently added some error-handling to it, using window.onerror to catch them. This sometimes works and sometimes doesn't; if I introduce a...
1
by: Jake G | last post by:
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...
3
Plater
by: Plater | last post by:
I am using the onerror event for the image tag in an attempt to save overhead for my server (which will be on a microprocessor) Basicly it tries to load the images from a real server on the...
5
by: test9991014 | last post by:
Hi, I gather that Javascript standard function names are case sensitive and they follow the old Smalltalk manner of applying case e.g. thisName, however I am curious, I see "onerror" mentioned...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.