Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-03
4
Medium Priority
?
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
dwaldner earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 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