By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,963 Members | 1,863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,963 IT Pros & Developers. It's quick & easy.

onError problem loading an image

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.