Results 1 to 7 of 7

Thread: listbox

  1. #1
    Guest

    Post

    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

  2. #2
    Addicted Member
    Join Date
    Jan 1999
    Posts
    239

    Post

    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

  3. #3
    Guest

    Post

    thanks for the fast reply. but i need the code in vbscript as i'm using asp. tq

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

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

  5. #5
    Guest

    Post

    Thank you very much, I will try it .

  6. #6
    Guest

    Post

    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.

  7. #7
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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
  •  



Click Here to Expand Forum to Full Width