Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alternate image if one doesn't exist?

Status
Not open for further replies.

TAMSIN

Programmer
Sep 6, 2000
31
GB
Any ideas please:

I have a page which displays a list of products from the database. For each product I also want to display an image. The images are all named based on the ProductID from the database - ie 1.gif, 2.gif etc.
However, for some product IDs , there is no image. In this case, I want to display a standard "No picture available" GIF. Is there a way in HTML to have alternate image if one isn't found? At the moment, I'm using ASP to see if the image exists, and if not setting the img source in ASP to the alternate image, but I'm a bit concerned about performance. Current code shown at end...
Thanks, Tamsin

Code:
<% var fso = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
    var filespec = &quot;../products/&quot; + rstProduct.Fields.Item(&quot;ProdID&quot;).Value + &quot;.gif&quot;;
if (fso.FileExists(Server.MapPath(filespec))) { %> 
        <img src=&quot;../products/<%=(rstProduct.Fields.Item(&quot;ProdID&quot;).Value)%>.gif&quot;> 
 <% } else {  %> 
        <img src=&quot;../images/NoPic.gif&quot;> 
<% } %>

[sig][/sig]
 
Maybe you should add the field &quot;ImageUrl&quot; to the database, and if the ImageUrl value is empty or null then put in the alternate image. The value to be stored in this field would be something like:
'../images/1.jpg'
[sig][/sig]
 
Thanks for the reply - I spose I should do it that way really, I just thought it might be simpler to use the prodID for the image name & not bother having an image name field. But I guess I was wrong. Oh well...
Thanks
Tamsin [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top