PDA

Click to See Complete Forum and Search --> : listbox


Dec 15th, 1999, 10:14 AM
how to select one item from one listbox and add it to another list box? i have tried to use listbox.getvalue(), listbox.additem()...but they don't work. please help! thank you

johnpc
Dec 15th, 1999, 11:36 AM
'Put two List Boxes on a Form
'and add the following to the
'General Declarations Section
Option Explicit
Dim Player(0 To 2) As Variant
Dim I As Integer

Private Sub Form_Load()

Player(0) = "Miggey McMoo" ' Enter data into array
Player(1) = "Alf Hinshaw"
Player(2) = "Woofer Dean"

For I = 0 To 2 ' Add names to list.

List1.AddItem Player(I)
Next I

End Sub

Private Sub List1_Click()
List2.AddItem Player(List1.ListIndex)
End Sub

Dec 15th, 1999, 12:20 PM
thanks for the fast reply. but i need the code in vbscript as i'm using asp. tq

Clunietp
Dec 15th, 1999, 03:25 PM
Here's a little something I threw together for you Dany -- you said you were using ASP so this does it using server side VBScript

Tom


<%@ Language=VBScript %>

<HTML>
<HEAD>
</HEAD>
<BODY>

<%
dim MySelections
dim MovedSelections
redim MovedSelections(0)

myselections = split(request.form("lst1"), ",")

%>

<form name=form1 method=post>

<P>
<SELECT name=lst1 multiple=true>
<%
Call CheckForOption("TOM")
call CheckForOption("BOB")
%>

</SELECT>
</P>

<P>
<SELECT name=lst2 multiple=true>
<%
Call ListMovedOptions
%>

</SELECT>
</P>
<INPUT TYPE=SUBMIT>
</form>

</BODY>
</HTML>

<%

Sub CheckForOption(OptionName)

dim bFound
dim I

bfound = false

if ubound(myselections) >= 0 then

for I = 0 to ubound(myselections)

if ucase(trim(myselections(I))) = ucase(trim(optionname)) then
bFound = true
exit for
end if
next

end if

if bfound = false then
response.write "<OPTION>" & OptionName & "</OPTION>"
else
redim preserve movedselections(ubound(movedselections) + 1)
movedselections(ubound(movedselections)) = OptionName
end if

end sub

Sub ListMovedOptions

dim I

for I = 1 to ubound(movedselections)
response.write "<OPTION>" & movedselections(i) & "</OPTION>"
next

end sub
%>

Dec 16th, 1999, 08:24 AM
Thank you very much, I will try it .

Dec 16th, 1999, 12:01 PM
can i do it using client script. in the previous server script, the page will reload everytime u add an element from listbox1 to listbox2.

can i do this:
when i select an item form listbox1 and click the add button, a copy of that item will appear in listbox2(the item in listbox1 is not deleted). meaning, when i repeat the process 3 times with 3 different items. 3 items will appear in listbox2.

i tried to solve this problem for bout a week now. please help. thank you.

Clunietp
Dec 16th, 1999, 12:05 PM
If you want to do it on the client side using VBScript, you will leave out Netscape and old MSIE users.

If you want to keep the list between page refreshes (using server side logic), you can add that into the code I wrote.