Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a dropdown list to allow selection of different directory

Status
Not open for further replies.

flyclassic22

Technical User
Oct 1, 2002
54
0
0
SG
Hi, I've this current script(ASP) that need modification which i've stucked.
My current script work this way, whenever my webpage starts it will go into a specific folder and search for extention ".xml" files and will list them out in a drop down list.

<%


Private Function getFilesByType(strFolder, strType)
'getFilesByType
' returns an Array of files for a specific type in a folder
' if no files where found returns null
Dim objFSO, objFolder, fileItem, fileCollection, arrFiles, i
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFolder = objFSO.GetFolder(strFolder)
Set fileCollection = objFolder.Files
response.write(&quot;<select name=&quot;&quot;xmlfileid&quot;&quot; onclick=&quot;&quot;showpreview_brief(selection.xmlfileid.value)&quot;&quot;>&quot;)

i = 0
For Each fileItem in fileCollection
If (lCase(Right(fileItem.name, len(fileItem.name) - InStr(fileItem.name, &quot;.&quot;))) = lCase(strType)) Then
If (i <> 0) Then
arrFiles = arrFiles & &quot;;&quot;
End If
i = i + 1
response.write(&quot;<option value=&quot;&quot;xmldata/&quot; &fileItem.name &&quot;&quot;&quot;>&quot; &fileItem.name)




'arrFiles = arrFiles & fileItem.name

End If
Next
Set objFSO = Nothing
Set objFolder = Nothing
Set fileCollection = Nothing
If (isNull(arrFiles) Or arrFiles = &quot;&quot;) Then
getFilesByType = Null
Else
getFilesByType = Split(arrFiles, &quot;;&quot;)
End If
response.write(&quot;</select>&quot;)

End Function


getFilesByType server.mappath(&quot;/MyProj/xmldata&quot;), &quot;xml&quot;

%>



However, i wanted to add another drop down list beside to allow user to select a specfic web server directory (for exame /MyProj/A/xmldata/ , /MyProj/B/xmldata/)
before it will display the xml drop down list with a list of the xml files. Meaning, user can select a directory from a drop down list and it wil automatically create another drop down list listing their xml files, in other words dynamic. I'm very confused as how to implement it into my current script. Can anybody help me solve?
 
Hello,
I would work like this:
make a page with the selectbox for the different directories.
in the select tag add an onChange event:

<select onChange=&quot;location.href='mypage.asp?folder='+this.value;&quot;>

that way you reload the page giving you the right folder selection. Now you can use your function to display the xml files selectbox.

You should add something that checks wether a folder is selected or not. When no folder is selected you shouldn't add the selectbox with xml files.

If not IsEmpty(request(&quot;folder&quot;)) Then
getFilesByType ...
End If

Of course it depends on how many directories you have with xml files. If only a few, you could opt to create different select boxkes for every directory and let a javascript function handle which ones should be shown (as a function of the selected value for the directories-dropdown).

But I guess reloading the page is much easier.

Hope this helps...

Let me know if you have more questions.
 
hi thanks... that's a great help to me.
But i've a problem now, i need my dropdownlist for directory to be &quot;selected&quot; when user select the choice. How do i do it? you know? I've done it in javascript to make it done, but it can't work again. sigh....hope you can help

<form name=&quot;selection&quot; method=&quot;post&quot; action=&quot;savexml.asp&quot;><div align=&quot;left&quot;><font size=1 face=&quot;Verdana&quot; color=&quot;#000000&quot;>XML file</font></div>

<div align=&quot;left&quot;> <select name=&quot;blabla&quot; onChange=&quot;location.href='selectionofstyle.asp?folder='+this.value;&quot;>
<option value=&quot;/MyProj/EG3251/&quot; >EG3251
<option value=&quot;/MyProj/xmldata/&quot;>xmldata
<option value=&quot;/MyProj/ta/&quot;>Others
</select>
<SCRIPT LANGUAGE=&quot;javascript&quot;>

var obj=eval(&quot;document.forms[1].blabla&quot;);
for(j=0;j<obj.options.length;j++)
{
if(&quot;<%request(&quot;folder&quot;)%>&quot;==obj.options[j].value)
{
obj.options[j].selected=true;
}
}


</SCRIPT>

<%


Private Function getFilesByType(strFolder, strType)
'getFilesByType
' returns an Array of files for a specific type in a folder
' if no files where found returns null
Dim objFSO, objFolder, fileItem, fileCollection, arrFiles, i
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFolder = objFSO.GetFolder(strFolder)
Set fileCollection = objFolder.Files
response.write(&quot;<select name=&quot;&quot;xmlfileid&quot;&quot; onclick=&quot;&quot;showpreview_brief(selection.xmlfileid.value)&quot;&quot;>&quot;)

i = 0
For Each fileItem in fileCollection
If (lCase(Right(fileItem.name, len(fileItem.name) - InStr(fileItem.name, &quot;.&quot;))) = lCase(strType)) Then
If (i <> 0) Then
arrFiles = arrFiles & &quot;;&quot;
End If
i = i + 1
response.write(&quot;<option value=&quot;&quot;xmldata/&quot; &fileItem.name &&quot;&quot;&quot;>&quot; &fileItem.name)




'arrFiles = arrFiles & fileItem.name

End If
Next
Set objFSO = Nothing
Set objFolder = Nothing
Set fileCollection = Nothing
If (isNull(arrFiles) Or arrFiles = &quot;&quot;) Then
getFilesByType = Null
Else
getFilesByType = Split(arrFiles, &quot;;&quot;)
End If
response.write(&quot;</select>&quot;)

End Function


If not IsEmpty(request(&quot;folder&quot;)) Then
if request(&quot;folder&quot;) = &quot;/MyProj/xmldata/&quot; then
getFilesByType server.mappath(&quot;/MyProj/xmldata/&quot;), &quot;xml&quot;
else
getFilesByType server.mappath(&quot;/MyProj/EG3251/&quot;), &quot;xml&quot;
end if
End If


%>
 
actually my project is ending, i stil can't solve that selected bug for my drop down list , can you help me, pleasee.?
MSN messager/email
flydx_007@msn.com

hope you can help me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top