Skip to main content
Inspiring
February 19, 2008
Question

Retrieve folder contents to populate drop down list

  • February 19, 2008
  • 2 replies
  • 354 views
Hi,

I am using the following code to list the contents of a specific folder on
my server in a drop down menu. This works perfectly. However, I want the
default value that is selected upon loading the page to be equal to a value
in a recordset :

<%=(Company.Fields.Item("Logo").Value)%>

Can anyone show me how to modify the code to make the default the above
value?

<select name="logo" id="logo" style="width:175px;">
<option value="blank.gif" ></option>
<%
dim jm_fso, jm_file, jm_types, jm_path, jm_folder,jm_show,jm_i,jm_ext
jm_ext=true
jm_path = "../media/" & (Company.Fields.Item("CompanyID").Value) & "/logos/"
jm_types = split(replace("asp,html, jpg, gif"," ",""),",")
Set jm_fso = Server.CreateObject("Scripting.FileSystemObject")
Set jm_folder = jm_fso.GetFolder(Server.MapPath(jm_path))

For Each jm_file in jm_folder.Files
jm_show=false
for jm_i=0 to ubound(jm_types,1)
If lcase(right(jm_file.name,3)) = jm_types(jm_i) then jm_show=true
next
If jm_show=true then
if jm_ext=true then
response.write "<option value=""" & jm_File.Name & """>" & jm_File.Name &
"</option>" &vbcrlf
else
response.write "<option value=""" & jm_File.Name & """>" &
mid(jm_File.Name,1,len(jm_File.Name)-4) & "</option>" &vbcrlf
end if
end if
next
set jm_file=nothing
set jm_folder = nothing
set jm_fso=nothing%>
</select>

I'm working on DW8, Windows, ASP VBScript

Thanks!


This topic has been closed for replies.

2 replies

Inspiring
February 20, 2008
Hi Mike,

Much obliged for the help! At first I couldn't get the code to work, but
then I realised there was an extra '=' just after your initial IF. I removed
it and it works fine now! Yay!

"MikeL7" <webforumsuser@macromedia.com> wrote in message
news:fpge86$bu0$1@forums.macromedia.com...
> Try adding this to your code Notice the extra if statement that is added
> in the
> middle
>
> <%
> dim jm_fso, jm_file, jm_types, jm_path, jm_folder,jm_show,jm_i,jm_ext
> jm_ext=true
> jm_path = "images/"
> jm_types = split(replace("asp,html, jpg, gif"," ",""),",")
> Set jm_fso = Server.CreateObject("Scripting.FileSystemObject")
> Set jm_folder = jm_fso.GetFolder(Server.MapPath(jm_path))
>
> For Each jm_file in jm_folder.Files
> jm_show=false
> for jm_i=0 to ubound(jm_types,1)
> If lcase(right(jm_file.name,3)) = jm_types(jm_i) then jm_show=true
> next
> If jm_show=true then
> if jm_ext=true then
> response.write "<option value=""" & jm_File.Name & """"
>
> If =(Company.Fields.Item("Logo").Value)= jm_File.Name THEN
> response.write " selected=""selected"""
> End If
>
> response.write ">" & jm_File.Name & "</option>" &vbcrlf
> else
> response.write "<option value=""" & jm_File.Name & """>" &
> mid(jm_File.Name,1,len(jm_File.Name)-4) & "</option>"
> end if
> end if
> next
> set jm_file=nothing
> set jm_folder = nothing
> set jm_fso=nothing
> %>
> </select>
>


Inspiring
February 20, 2008
Try adding this to your code Notice the extra if statement that is added in the middle