Solved

create dynamic dropdown in HTA with VBSCRIPT

Posted on 2011-03-09
5
2,572 Views
Last Modified: 2012-06-27
hi,
    i am trying to populate a drop down in a HTA with VBScript.   I am lost on how to pass the values from the script to the SELECT in HTML.  i would appreciate any help with passing the values to the HTML dropdown

thanks

 
<html>
<head>
<title>create</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Create Accounts"
	 Borderstyle="raised"
	 Border="thin"
	 ICON="Globe.ico" 
     SCROLL="yes"
	 SYSMENU="yes"
	 VERSION="1.4"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="maximize"
	 

>

<script LANGUAGE="VBScript">

On Error Resume Next  

sub populatename()

Dim fso, folder, files, NewsFile,sFolder    
Set fso = CreateObject("Scripting.FileSystemObject")  
sFolder = "\\server\share"
If sFolder = "" Then      
Wscript.Echo "Path Does Not Exist"      
Wscript.Quit  
End If  
Set folder = fso.GetFolder(sFolder)  
Set files = folder.Files    
For each folderIdx In files    
msgbox folderIdx.Name
Next 

End Sub
 
</script>


</HEAD>


<BODY>
<B><FONT color=#107FAC>User/Group Location:<TD><select NAME=OULocation
  <option value="">
<option value="nill">-- Select Location --
<option value="city1">city1
<option value="city2">city2
<FORM NAME="Create">
 /FORM>

</BODY>



</HTML>

Open in new window


0
Comment
Question by:supportAB
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 35088904
Hi, do you want something like this?

Regards,

Rob.
<html>
<head>
<title>create</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Create Accounts"
	 Borderstyle="raised"
	 Border="thin"
	 ICON="Globe.ico" 
     SCROLL="yes"
	 SYSMENU="yes"
	 VERSION="1.4"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="maximize"
>
<script LANGUAGE="VBScript">
Sub Window_OnLoad()
	Set objFSO = CreateObject("Scripting.FileSystemObject")  
	sFolder = "\\server\share"
	If sFolder = "" Then
		MsgBox "Path Does Not Exist"
	Else
		For Each objFile In objFSO.GetFolder(sFolder).Files
	        Set objNewOption = Document.CreateElement("OPTION")
	        objNewOption.Text = objFile.Name
	        objNewOption.Value = objFile.Path
	        Create.OULocation.Add(objNewOption)
		Next
	End If

End Sub
 
</script>


</HEAD>


<BODY>
<FORM NAME="Create">
	<FONT color=#107FAC>User/Group Location:</FONT>
	<select NAME=OULocation>
	<option value="nill">-- Select Location --</option>
	</select>
</FORM>
</BODY>
</HTML>

Open in new window

0
 

Author Comment

by:supportAB
ID: 35089103
thanks, perfect, thank you.  one more question.  now, when i select one of the citys from the dropdown how do i set the <option value=>?

for example:
 normally it would be:
<option value="city">
<option value="city1">

how can i set the option value=

thanks


0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 35089187
Hi, the value is set by this line:
              objNewOption.Value = objFile.Path

so, in this case, the value of each option is set to the full path of each file.

Regards,

Rob.
0
 

Author Closing Comment

by:supportAB
ID: 35094051
thank you for all your help
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35099545
No problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

730 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