Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

Help with using the fso to create a javascript array for use with a dynamic image display

Here's a toughie.  I'll start this in the asp forum as the core of the issue is asp but there's javascript involved as well.  

I'm trying to modify a script that I formerly used with a database call to work with the file system object.  It is part of an adminstration tool where the basic intent is to read a directory (of images in this case) and display that list in a select list.  The admin then selects one of the images and it is displayed immediately below the select list.  I've used this to good effect with database queries, but this time I need to see what is on the actual server, not what's in the database.

I've got the fso part working fine but can't figure out how to incorporate the javascript required to write the image array into the sub that runs the select list.  There's ultimately another piece to this where I'd like to be able to pass the designated image name identifier to the js function as well, so I would only have to have one resuable function, but that the next question...

Hope this is clear - code is below.
------------------------------------------------------------------------
<%
' recursive (calls itself) search function
SUB searchFolder(folder)
dim fil,file,filepath,fol
' get files colection from our folder object
Set fil = folder.files
' for each one lets get some info and store it in an array
FOR EACH file IN fil
' first chop off the root bit
filepath = RIGHT(file.path,(LEN(file.path) - LEN(root)))
' swap the seperators
filepath = REPLACE(filepath,"\","/")
' add path to filename
' write out the link
response.write "<option value=" & filepath & ">" & filepath & "</option>"
NEXT
END SUB

' script to make a link for all files under
' virtual dir, youll have to tidy the output a bit
DIM root,fso,fldr
function getFolderContents(byVal folderpath)
' set this to the root of your chosen dir
root = "D:\inetpub\c-b.com\igor\images\" & folderPath
' create a filesystem object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder(root)
call SearchFolder(fldr)
end function
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title></title>
<script>
var _img = new Array();
//    _img[0] = new Image(); _img[0].src="/images/locations/officePhotos/arlington.jpg";
function doIt(_obj)
{
if(!_obj)return;
var _index = _obj.selectedIndex;
if(!_index)return;
var _item  = _obj[_index].value;
if(!_item)return;
if(_item<0 || _item >=_img.length)return;
document.images["serviceImage"].src=_img[_item].src;
}
</script>
</head>
<body>
<form action="selectImages.asp" method="post">
<table cellspacing="0">
<tr>
<td style="padding-bottom:10px;">Image:</td>
<td style="padding-bottom:10px;">
<select name="serviceImage" class="serviceInfo" onChange="doIt(this);">
<option value="">Select a service image
<%=getFolderContents("services\standard\")%>
</select>
</td>
</tr>
<tr>
<td></td>
<td style="padding-bottom:15px;"><img src="/images/services/standard/<%=serviceImage%>" border="0" name="serviceImage"></td>
</tr>
</table>
</form>
</body>
</html>
0
saabStory
Asked:
saabStory
  • 3
1 Solution
 
dwaldnerCommented:
Ok, from what I gathered, you want to have a select box filled with images stored on the server, and you want to have them displayed below when you select one.  Here's what I would do


<script language="javascript">
function doIt(objBox)
{
  if (objBox.selectedIndex != -1)
  {
    document.getElementById("previewImage").src = objBox.options[objBox.selectedIndex].value;
  }
}
</script>

<select name="serviceImage" class="serviceInfo" onChange="doIt(this);">
<option value="">Select a service image</option>
<%=getFolderContents("services\standard\")%>
</select>

....put this below your select box....

<img src="some_temporary_blank_image" id="previewImage">

That should do what you want it to do...

Cheers,

Dan
 
0
 
dwaldnerCommented:
PS.  You'll probably have to tweak this a little, I wrote it pretty quickly, and it'll do what you need it to do, but you'll have to error-trap for times when the value="", etc....
0
 
saabStoryAuthor Commented:
Thanks - I see I need to do some work to get the correct path to come through for the image but that should be pretty easy.

Thanks for the help!
0
 
dwaldnerCommented:
No problem!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now