Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically know the image file not found

 
kavin clain
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In javascript I am loading an image tag using ImageObj.src = 'loadimg.do';.

It works fine. But if the image file not found this way, then I want to set a default image.

My question is how to know the action 'loadimg.do' could not find the requested image.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best to handle that on the server.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be better to do it on the server as mentioned.

There is a way to use



Eric
 
kavin clain
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using myeclipse. When I typed onerror... it was showing warning.
Then I checked http://www.w3schools.com/tags/tag_IMG.asp .

No such attribute defined for img tag. Even though,
I am going to try this code... but I think there should be one such attribute.
I tried the server side code & It is perfectly working.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
onerror is valid and it is not an attribute, it is a JavaScript event handler.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kavin clain wrote:I am using myeclipse.

What your IDE says is of no concern. IDEs are notoriously bad at client-side development.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic