PDA

View Full Version : new to javascript


dpkdayton
06-07-2004, 03:25 PM
I am brand new to javascript. To make matters worse, Im working with very few resources for information and code. I am working on a website that displays a jpg images. What I am looking for is a way to scan through a directory and check to see if the photo name exists, if not display a default image. If anyone can help me, I'd be greatfull.
Thanks,
Doug Kotnik

bocmaxima81
06-11-2004, 03:11 PM
I am brand new to javascript. To make matters worse, Im working with very few resources for information and code. I am working on a website that displays a jpg images. What I am looking for is a way to scan through a directory and check to see if the photo name exists, if not display a default image. If anyone can help me, I'd be greatfull.
Thanks,
Doug Kotnik

You can't do this with client-side JScript. You need to either get PHP, ASP, or some other server-side programming language running. Server-side JScript will work, but you have to have it installed. If you are running IIS, then you will already have ASP running and will need to do some research on how to pull directory listings.
One work-around I would suggest is to have your image sources contained as text strings in an array on a central JS file. Then run a for loop to check if the image they're requesting exists.
for (var i=0; i<myarray.length; i++) {
if (requestedImageName == myarray[i]) {
myImage.src = requestedImageName+".jpg";
}
else {
myImage.src = "default.jpg";
}
}

Hope that helps.
-colin

B500
06-14-2004, 12:18 PM
Perhaps you could try going to a website like www.w3schools.com or something to try one of their tutorials? they have an excellent step by step layout and lots of customizable examples to play with. Try It :)