Forum Moderators: open

Message Too Old, No Replies

display images and names of images thru drop down box

         

ajifri

12:29 am on Sep 6, 2003 (gmt 0)

10+ Year Member



Hi,
I made these codes to display images which are in specify folder and display the names of these images thru drop down box.
I need to make it on image, one drop down box with images name.
When I run the code it gave me many images and many drop down box

====
<html>
<head>
<script language="javascript">
<!--
function showimage()
{
if (!document.images)
return
document.images.pictures.src= document.mygallery.picture.options[document.mygallery.picture.selectedIndex].value
}
//-->
</script>
</head>
<body>
<p>
<%
' Create an instance of the FileSystemObject
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
' Create Folder Object
Set MyFolder=MyFileObject.GetFolder(Server.MapPath("/zad-alrida/images/products/"))
%>
<%
'Loop trough the files in the folder
FOR EACH thing in MyFolder.Files
%>
<form name="mygallery">
<img src="<%=thing.name%>" name="pictures" width="99" height="100">
<select name="picture" size="1" onchange="showimage()">
<option selected
value="<%=thing.name%>"><%=thing.name%></option>
</select>
<% next %>

</form>
=========
Do you have any solution for me :(

aspdesigner

8:31 pm on Sep 6, 2003 (gmt 0)

10+ Year Member



For your SELECT box, pull the FORM and SELECT statements out of the loop, just loop the OPTION tags.

If you want to display many pictures but just 1 SELECT box, you should make a loop for each, one to display the pictures, and one to generate the OPTION tags inside your select.

ajifri

9:57 pm on Sep 6, 2003 (gmt 0)

10+ Year Member



Hi,
Thanks for your reply, I did it before, but I got error when I wrote it like this
======
<form name="mygallery">
<img src="<%=thing.name%>" name="pictures" width="99" height="100">
<select name="picture" size="1" onchange="showimage()">
<%
'Loop trough the files in the folder
FOR EACH thing in MyFolder.Files
%>
<option selected value="<%=thing.name%>"><%=thing.name%></option>
<% next %>
</select>
</form>
it gaves me error, because the image is out of loop :(, and i only want one image not many images :(

please help me

aspdesigner

12:26 am on Sep 7, 2003 (gmt 0)

10+ Year Member



If you only want to display 1 picture, then you need to tell it which picture you want.

If you say "thing.name" outside of your For...Each loop, ASP has no idea what you're talking about.

If you just want to display a specific picture, then replace that with the name of the picture you want to display.

ajifri

7:51 am on Sep 7, 2003 (gmt 0)

10+ Year Member



Would you please give me an example :(

ajifri

6:37 am on Sep 8, 2003 (gmt 0)

10+ Year Member



any solution guys?

mattglet

1:08 pm on Sep 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what is the exact error when you try to only loop the option tag?

-Matt

aspdesigner

2:41 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



He's referring to "thing.name" outside of the For...Each.

ajifri, take that last example you gave, and replace the line with the image tag with this -

<img src="pictureIwanttodisplay.jpg" width="99" height="100">

then try it.