Solved

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

Posted on 2004-08-03
4
375 Views
Last Modified: 2008-01-16
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
Comment
Question by:saabStory
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
dwaldner earned 500 total points
ID: 11706180
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
 
LVL 3

Expert Comment

by:dwaldner
ID: 11706191
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
 

Author Comment

by:saabStory
ID: 11706357
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
 
LVL 3

Expert Comment

by:dwaldner
ID: 11706370
No problem!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now