PDA

Click to See Complete Forum and Search --> : Multiple selections in SELECT in ASP


noone
Aug 1st, 2000, 04:55 PM
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.

noone
Aug 1st, 2000, 05:23 PM
Well I figured it out if anyone else was wondering:

Dim EmployeeCount
EmployeeCount = Request.Form("Employees").Count
dim i
For i = 1 to EmployeeCount
Response.Write(Request.Form("Employees").Item(i))
Next

Serge
Aug 1st, 2000, 05:40 PM
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:

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