We help IT Professionals succeed at work.

get all values of select box in vbscript

SeanGraflund
SeanGraflund asked
on
Medium Priority
2,050 Views
Last Modified: 2008-02-26
I have a form that has a multiple select list box.  On my post page, how can I get all the values selected in that list box?

Before, all I've ever done is:
Request.Form("listbox"), and that would return the text of the selected item.  How can I return the value, of multiple items selected?

Thanks,
Comment
Watch Question

CERTIFIED EXPERT

Commented:
What you get is a comma separated string of the values of the selected items. Try this code:

<%=Request.Form("test")%>

<br>

<form method="post">

<select name="test" size="6" multiple>
     <option value="1">First
     <option value="2">Second
     <option value="3">Third
     <option value="4">Fourth
     <option value="5">Fifth
     <option value="6">Sixth
</select>

<input type="submit" value="go">

</form>
CERTIFIED EXPERT
Top Expert 2005
Commented:
something like this:

For Each strItem in Request.Form("listbox")
  Response.Write(strItem)
Next
Mark FranzProject Manager
CERTIFIED EXPERT

Commented:
And to create a result list with the values, use this syntax for your SQL string;

theList = Request.Form("listbox")
sql = "select * from [Table] where ID in (" & theList & ")Order by ID"

Explore More ContentExplore courses, solutions, and other research materials related to this topic.