Click to See Complete Forum and Search --> : Checking an image


rsherard3
11-09-2003, 09:33 PM
I am in a bind. I am working on a slide show that uses:

var image1 = new Image()
image1.src = gmtimgurl9
var image2=new Image()
image2.src = gmtimgurl8
var image3=new Image()
image3.src = gmtimgurl7
var image4=new Image()
image4.src = gmtimgurl6
var image5=new Image()
image5.src = gmtimgurl5
var image6=new Image()
image6.src = gmtimgurl4
var image7=new Image()
image7.src = gmtimgurl3
var image8=new Image()
image8.src = gmtimgurl2
var image9=new Image()
image9.src = gmtimgurl1
var image10=new Image()
image10.src = gmtimgurl
var image11=new Image()
image11.src = gmtimgurl
var image12=new Image()
image12.src = gmtimgurl
var image13=new Image()
image13.src = gmtimgurl
var image14=new Image()
image14.src = gmtimgurl
var image15=new Image()
image15.src = gmtimgurl

These variables load the image. I found a script to check the image to ensure it exists, but it doesn't work. What I am trying to do is check the image url to ensure the image is there. If not, then I will increment the step variable to go to the next image. Anyone have any suggestions? I'm stuck here. Thanks in advance!

Khalid Ali
11-09-2003, 10:01 PM
use the onerror event of the image object for this purpose

var image1 = new Image()
image1.onerror=dosomethig here
image1.src = gmtimgurl9

rsherard3
11-09-2003, 11:22 PM
Well, I have the following code:

var image1 = new Image()
if (image1.onerror) {
image1.src = gmtimgurl7
} else {
image1.src = gmtimgurl8
}

In theory, this should make image1.src equal to gmtimgurl7 if there is an error, correct? However, I am still getting a broken image displayed when the loop is run. Am I on the right track? Thanks!

rsherard3
11-11-2003, 02:22 PM
Ok. After trial and error, obviously, the above will not work. Here is code for two images I have:

var image1 = new Image()
image1.src = gmtimgurl9
var image2=new Image()
image2.src = gmtimgurl8

This should be pretty easy, but I cannot figure out how to do it. If the second image is not found, then the first image should be loaded in its place. So, I would then have two slides of the same image instead of one image and a blank image. Does anyone know how I can do that? I have tried the onError, but nothing there seems to work. Any help is greatly appreciated. Thanks in advance!