|
-
Dec 15th, 1999, 11:14 AM
#1
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
-
Dec 15th, 1999, 12:36 PM
#2
Addicted Member
Code:
'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, 01:20 PM
#3
thanks for the fast reply. but i need the code in vbscript as i'm using asp. tq
-
Dec 15th, 1999, 04:25 PM
#4
Guru
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
Code:
<%@ 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, 09:24 AM
#5
Thank you very much, I will try it .
-
Dec 16th, 1999, 01:01 PM
#6
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.
-
Dec 16th, 1999, 01:05 PM
#7
Guru
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|