Print Page | Close Window

Pesky red x (no img) boxes

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=13297
Printed Date: 30 March 2026 at 7:51pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Pesky red x (no img) boxes
Posted By: rocketdawg
Subject: Pesky red x (no img) boxes
Date Posted: 10 January 2005 at 8:05pm
I have several thousand imgs in file. They are brand images corresponding to the product that my customer is looking at. Therefore, in the product description box I have this to call the appropriate image:
 
response.write "<img src=""imgs/" & strName & ".jpg"">"
 
Here is my question: Is there a way to substitute a smiley face, or a text string, instead of the pesky red x if no image is found in my file?
 
My wife is not liking my baldness from this. Any ideas anyone?
 
Thanks in advance.



Replies:
Posted By: dpyers
Date Posted: 10 January 2005 at 10:23pm
It's a client-side browser issue. That particular red X only appears in IE. Other browsers use a different image for no image found.
 
With asp.net, you can set up an http handler to intercept image requests and serve up something special if they're not found.
With scripting languages and html however, the page returns a status of 200 - OK - so no way to use anything like a custom 404 page to deal with the image.
 
Your only alternative to something like .net is to use your own script to serve images - e.g. <image src="myscript.asp?imagename=xxx.jpg">
 
Your script could then use fso to get the image and response.writebinary to serve it up. If you get an fso error, then serve up the alternate image.
 
Note: response.binarywrite (objrs("Field_Name")  will display an image from a database record set pulled by an sql statement.


-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: rocketdawg
Date Posted: 10 January 2005 at 10:30pm

I understand that. My real question, better put, is:

Is there a way to write this:?

If (" & strName & ".jpg") = nuthin, then response.write("smiley.jpg")
 
The part I'm having trouble with is: If (" & strName & ".jpg") = nuthin
 
I am having trouble getting my page to recognize that there is no image in my image folder to response.write in the first place!
BTW, strName is a valid variable passed from the previous page.
 
Did that make more sense?


Posted By: dpyers
Date Posted: 10 January 2005 at 10:41pm
I updated my previous post while you were posting, but what you'd need to do is use fso to see if the image exists or not,

-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: dpyers
Date Posted: 11 January 2005 at 12:43am
Try This...
<%
Function fncDoesFileExist(ByVal strFileName)
 dim objFSO
 dim strFilePath
 
 set objFSO= CreateObject("Scripting.FileSystemObject")
 
 strFilePath = Server.MapPath(strFileName)
 
 If objFSO.FileExists(strFilePath) then
     fncDoesFileExist = true
  else
     fncDoesFileExist = false
 End IF
 
 set objFSO= nothing
End Function
 
 
If fncDoesFileExist(strName & ".jpg") = true then
    response.write strName & ".jpg" 
    else
    response.write("smiley.jpg")
End IF

%>
 


-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: Greyth
Date Posted: 12 January 2005 at 7:06pm
Or you can use the same method that is used to get images using a BLOB field in a database and then make that the 404 error page for your image directory.

Since it is a 404 error, you would also probably want to add a line to reset the response status to whatever the header is for jpg.

That would basicly just save your page from having an extra hit on the hard drive and a little bit of code for regular loading. You could also have it send a variable through the querystring that you could use to track down products without images.

Check the article here:
http://support.microsoft.com/kb/173308/EN-US/


Posted By: Gullanian
Date Posted: 13 January 2005 at 10:19am
You can add a single line of javascript to the img tag that displays a different image if one isn't found.  Can't remeber where I saw it though, might want to look on google.


Posted By: dj air
Date Posted: 13 January 2005 at 10:26am
onerror=this.SRC="image path to error image"

i believe thats it.

insert that within the image tag ie <img src="" onerror=this.src="">


Posted By: rocketdawg
Date Posted: 13 January 2005 at 11:47am
dj air,
 
You got it. Here is the line. If my product has no pic associated with it, Marvin the Martian tells you that - instead of the pesky red x.
 
I thank you very much.
 
response.write "<img src=""imgs/" & strName & ".jpg"" onerror=this.src=""/imgs/marvin.gif"">"
 
Have a good day all!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net