onError problem loading an image

J

Jürgen Heyn

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
 
I

Ivo

Jürgen Heyn said:
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
^^^^^
 
I

Ivo

Ivo said:
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
 
R

Richard Cornford

Ivo wrote: said:
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.
 
J

Jürgen Heyn

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
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top