Click to See Complete Forum and Search --> : Image selector.


cmccomas
06-18-2003, 09:14 AM
Hey folks, just a newbie here. Really don't know JS at all, usually rely on PHP, but I needed JS for something on my site and found something very close to what I needed. I need to know if I can add something to this code, or if there is a code already out there to load the images automatically from a directory on my webserver.

<script language="javascript">
<!--

function showimage()
{
if (!document.images)
return
document.images.pictures.src=
document.mygallery.picture.options[document.mygallery.picture.selectedIndex].value
}
//-->
</script>

<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><form name="mygallery"><p><select
name="picture" size="1" onChange="showimage()">
<option selected value="me.gif">Picture of me</option>
<option value="myaunt.gif">Picture of my aunt</option>
<option value="brother.gif">Picture of my brother</option>
</select></p>
</form>
</td>
</tr>
<tr>
<td width="100%"><p align="center"><img src="me.gif" name="pictures" width="99"
height="100"></td>
</tr>
</table>

cmccomas
06-18-2003, 10:51 AM
Anyone have an idea how to do this?

Khalid Ali
06-18-2003, 11:03 AM
JavaScript does not have the ability to read files a from a system.
for theimages though,what you can do is create uniform naming convention and then you can use that convention load images from the absolute or relative path location.

cmccomas
06-18-2003, 11:05 AM
Thanks.

what you can do is create uniform naming convention and then you can use that convention load images from the absolute or relative path location

Can you give me an example?

Khalid Ali
06-18-2003, 11:20 AM
suppose you have 10images in a folder named images

all of your images are named as
"image1.gif"
"image2.gif"
"image3.gif"
.................
.................
"image9.gif"
"image10.gif"

now you can pre aload all of the iamges in the folder like this

var imgArr = new Array();
for(var x=0;x<10;x++){
var img = new Image();
img.src = "images/image+"+(x-1)+".gif";
imgArr [x] = img;
}