windows 过滤其他下拉菜单的 HTA vbscript 下拉菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6114733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTA vbscript dropdown that filters other dropdowns
提问by Jim B
I fairly new to creating HTA's, how can I create a dropdown that will filter the results for other dropdowns? I have a database with sitename and state and what I would like is to populate the site dropdown after state is selected with just those records where the state that was selected matches.
我对创建 HTA 还很陌生,如何创建一个下拉列表来过滤其他下拉列表的结果?我有一个包含站点名称和状态的数据库,我希望在选择状态后仅使用与所选状态匹配的那些记录来填充站点下拉列表。
回答by rd1966
Here's a very simple HTA which populates one dropdown based on the selection from another. Should be easy to adapt to read from your database.
这是一个非常简单的 HTA,它根据从另一个下拉列表中的选择填充一个下拉列表。应该很容易适应从您的数据库中读取。
<html>
<head>
<title>Test</title>
<HTA:APPLICATION
APPLICATIONNAME="Test"
ID="Test"
VERSION="1.0"/>
</head>
<script language="VBScript">
Sub Window_OnLoad
Populatedropdown1
End Sub
Sub Populatedropdown1
For i = 0 To 5
Set opt = document.createElement("option")
opt.Value = i
opt.Text = "Option " & CStr(i)
dropdown1.add opt
Next
End Sub
Sub Populatedropdown2
For Each opt in dropdown2.Options
opt.RemoveNode
Next
For i = dropdown1.value To 10
Set opt = document.createElement("option")
opt.Value = i
opt.Text = "Option " & CStr(i)
dropdown2.add opt
Next
End Sub
</script>
<body bgcolor="white">
<p>Select 1: <select name="dropdown1" id="dropdown1" onchange="Populatedropdown2"></select></p>
<p>Select 2: <select name="dropdown2" id="dropdown2" ></select></p>
</body></html>
Does that help?
这有帮助吗?
回答by Blitzcrank
What if my first dropdown list will list all sub_folder in a parent folder, when i pick up one sub-folder from 1st dropdown, it will generate the secend dropdown list which will list all sub folder in there and so on? How to do this?
如果我的第一个下拉列表将列出父文件夹中的所有 sub_folder,当我从第一个下拉列表中选择一个子文件夹时,它将生成第二个下拉列表,其中将列出所有子文件夹等等?这该怎么做?
<HEAD>
<TITLE>K Drive Program Structure</TITLE>
<HTA:APPLICATION ID="Eeee"
APPLICATIONNAME="C Drive "
BORDER="Dialog"
CAPTION="Yes"
SCROLL="NO"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="Yes"
WINDOWSTATE="maximize">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="VBScript">
Sub UpdateList
For Each opt In list.Options
opt.RemoveNode
Next
Set fso = CreateObject("Scripting.FileSystemObject")
For Each f In fso.GetFolder("C:\WORK").SubFolders
Set opt = document.createElement("OPTION")
opt.Text = f.Name
opt.Value = f.Path
list.Add(opt)
Next
End Sub
Sub EnumSubFolders
Set fso = CreateObject("Scripting.FileSystemObject")
For Each opt In list.options
If opt.selected Then
Set sf = fso.GetFolder(opt.value).SubFolders
Exit For
End If
Next
End Sub
</SCRIPT>
<H2>K Drive Structure</H2>
<P>CUSTOMER NAME
<select id="list" name="list" onkeydown="UpdateList" onChange="EnumSubFolders"></select><P>
<BR>
<BR>
<Input Type = "Button" Name = "btn01" VALUE = "SUBMIT">
<Input Type = "Button" Name = "btn02" VALUE = "CLOSE">
<BR>
<BR>
</BODY>