PDA

View Full Version : Using VBScript to add listbox item


gigsvoo
12-13-2001, 05:04 AM
Hi there,

I need to add a item to the listbox using VBScript like this:

Sub button1_onclick()
select1.???
End Sub

Dr. Web
12-13-2001, 11:53 AM
vbscript works only in IE. Are you designing specifically for IE users?

Jon Hanlon
12-13-2001, 05:04 PM
Sub button1_onclick()
set newOption = document.createElement("OPTION")
newOption.Text = "A new Option"
newOption.Value = "N"
select1.Add newOption
End Sub


The default placement of the new option is at the end of the list. You can specify placement with the optional second parameter:
select1.Add newOption,0 ' adds to the start of the list
select1.Add newOption,2 ' inserts it as the new 3rd entry.

You can also set other properties of the new option:
newOption.DefaultSelected = True
newOption.Selected = False

In Javascript you can do the same with:

select1.options[select1.length] = new Option("A new Option","N",true,false)