Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Add items to a list box using script in HTA

522 views
Skip to first unread message

XP

unread,
May 5, 2007, 2:12:01 PM5/5/07
to
I'm working on a small HTA app and I want to add some items from an array to
a list box using VBScript.

I cannot figure out how to do it...

Can someone please post a generic code example that does it?

Thanks much in advance.

Ken

unread,
May 5, 2007, 3:56:43 PM5/5/07
to

<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>

Ayush

unread,
May 5, 2007, 5:36:20 PM5/5/07
to
[XP]s message :

> I'm working on a small HTA app and I want to add some items from an array to
> a list box using VBScript.

> 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

0 new messages