Results 1 to 3 of 3

Thread: Multiple selections in SELECT in ASP

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    Hi, I feel kind of stupid for asking this but I need to know how to check what was selected on a multiple listbox.
    eg:
    <SELECT id=select1 multiple name=Employees size=5>
    some options here
    </select>

    How would I use ASP code to find out what was selected. And if anyone could point me to a page about checking different form elements by ASP it would be very appreciated.
    "People who think they know everything are a great annoyance to those of us who do."

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    Well I figured it out if anyone else was wondering:
    Code:
    Dim EmployeeCount
    EmployeeCount = Request.Form("Employees").Count
    dim i
    For i = 1 to EmployeeCount
    	Response.Write(Request.Form("Employees").Item(i))
    Next
    "People who think they know everything are a great annoyance to those of us who do."

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    The code you have will work if you have a submit button, but if you have a regular button then you can do it using a client side scripting:
    Code:
    <HTML>
    <HEAD>
    
    <SCRIPT LANGUAGE=vbscript>
    
    Sub GetCount() 
    	Dim colOptions
    	Dim i
    	Dim strValues
    	
    	Set colOptions = frmMyForm.lstList.Options
    
    	For i = 0 To colOptions.length - 1
    		If colOptions(i).Selected Then
    			strValues = strValues &  colOptions(i).Value & vbCrLf
    		End If
    	Next
    	window.alert strValues
    	
    
    End Sub
    
    </SCRIPT>
    </HEAD>
    <BODY>
    
    <P> </P>
    
    
    <FORM name=frmMyForm action=Serge.asp>
    
    <SELECT name=lstList multiple>
    	<%For i = 1 To 10%>
    		<OPTION Value=<%="Item" & CStr(i)%>><%="Item" & CStr(i)%></OPTION>
    	<%Next%>
    </SELECT>
    
    <INPUT type="button" value="Count Selected Items" name=cmdCount onclick="GetCount">
    </FORM>
    
    </BODY>
    </HTML>
    [Edited by Serge on 08-01-2000 at 06:42 PM]

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