Solved

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

Posted on 2004-08-03
4
384 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
RegEx Help - open to other simple suggestions 8 58
jquery to restrict certain words from input in form 11 40
JS does not refresh 6 30
MS SQL + date 6 23
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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