Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

15 Experts available now in Live!

Get 1:1 Help Now