Halu and welcome aboard!
Yes, there is a solution to your problem, in fact I think your description was very well put.
Take a look at this code, written by Danne [or choose Spookster's version if you find it more attractive] in this thread
<img id="dynImg" onError="this.src='noimageavail.jpg';">
Hope that helps,