Solved

create dynamic dropdown in HTA with VBSCRIPT

Posted on 2011-03-09
5
2,383 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you for all your help
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
No problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

763 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

6 Experts available now in Live!

Get 1:1 Help Now