> I have an application where I list several items on a page and display an
> image for that item based on a reference number (ie, productnum+.jpg). The
> database table does not tell me whether there is an image for that item
> and there are many that do have one.
>
> I'd like to display an alternate image (or nothing at all) when there is
> no image present, but I can't see using an <CFIF FileExists> for every
> item for 50 or so on a page. Plus, I can't even do that because I'm
> grabbing the images from a different server via http only (<IMG
> SRC="http://otherserver/path/number.jpg>)...

Tony,

Let the client-side box do the work, with JavaScript. Here's a demo page
that tests for the presence of an image, and swaps the missing image with a
default image... I'm sure you can modify it to your needs:

<html>
<head>
<title>Image Not Found Test</title>
<script language="JavaScript"><!--
// make DARN sure this replacementImage file IS
// present and accounted for, or you'll get a nasty
// loop with repeated calls to this function.
// Also, enter the exact pixel dimensions of the
// replacement image. IE will respect it and resize...
// NS4 will load the replacementImage in the same
// dimensions as the missing one
var replacementImage = new Image(128,124);
replacementImage.src = '/images/notFound.gif';
function imageLoadError(myImage){
  myImage.src=replacementImage.src
return false;
}
// -->
</script>
</head>
<body>
<img src="thisfilenotavailable.jpg"
     onError="imageLoadError(this);">
</body>
</html>


A big thanks to Jeff Howden at evolt.org for pointing out the onError event
handler for <img> tags to me initially.

Ron Allen Hornbaker
President/CTO
Humankind Systems, Inc.
http://humankindsystems.com
mailto:[EMAIL PROTECTED]




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to