I cannot figure out how to do it...
Can someone please post a generic code example that does it?
Thanks much in advance.
<HTML>
<head>
<TITLE>Dynamic Selection Options
</TITLE>
<HTA:APPLICATION ID="objDynamDelOps"
APPLICATIONNAME="DynamicSelectionOptions" WINDOWSTATE="normal">
</head>
<script language=VBScript>
option explicit
Sub Main
Dim I
Dim MonthsofYear
MonthsofYear =
Split("January~January~February~March~April~May~June~July~August~September~October~November~December","~")
'remove any options that may already be in the listbox
For I = 0 TO document.all("Months").options.length - 1
document.all.Months.remove(0) 'remove option zero and option one
becomes option zero
Next
For I = Lbound(MonthsofYear) to Ubound(MonthsofYear)
AddMonthSelOpt(MonthsofYear(I))
Next
End Sub
'This routine dynamically adds items to the "Months" listbox
Function AddMonthSelOpt(value)
Dim I
Dim TempOption
Set TempOption = document.createElement("Option")
TempOption.value = value
TempOption.text = value
'this will prevent adding duplicate options
For I = 0 TO document.all("Months").options.length - 1
If document.all("Months").options(I).value = value Then
Exit Function
End If
Next
document.all.Months.add(TempOption)
End Function
Function SelectMonth
MsgBox "You Selected " &
document.all("Months").options(document.all.Months.selectedIndex).Value
'or you could process the .Text
End Function
</SCRIPT>
<BODY onload="Main" >
<SELECT NAME="Months" OnChange="SelectMonth">
<OPTION VALUE="Default"> The program will replace this option from an
array
</SELECT>
</BODY>
</HTML>
> Can someone please post a generic code example that does it?
options=Array("A","B","C","D","E")
For i=0 to UBound(options)
set op=Document.CreateElement("Option")
op.text=options(i) 'to set value,use: op.value=xx
sel.add(op) 'sel = select element
Next