Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Requesting more than one value from a <select> list

Status
Not open for further replies.

silversurfer

Programmer
Nov 8, 2000
19
GB
I have got a <select> list set to multiple, so the user can choose more than one options.Easy..., but how can I request these values? I know how it works with one value, but passing on more than one value from one list gives me a headache :(
I though the following code would work, but it doesn't

<%
For Each item In Request.Form(&quot;formname&quot;)
Response.Write item & &quot;<BR>&quot;
Next
%>

or

<%
For I = 1 To Request.Form(&quot;formname&quot;).Count
Response.Write Request.Form(&quot;formname&quot;)(I) & &quot;<BR>&quot;
Next
%>

Does anybody has got an idea?
 
This is just an example:
-----------------------------
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>

<form name=&quot;for1&quot; method=&quot;post&quot; action=&quot;mult_sel.asp&quot;>
<select name=&quot;sel1&quot; multiple>
<option value=&quot;1&quot;>1
<option value=&quot;2&quot;>2
<option value=&quot;3&quot;>3
</select>
<input type=&quot;submit&quot;>
</form>

</BODY>
</HTML>

------------------------------
mult_sel.asp
------------------------------

<%@language=vbscript%>

<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>

<%
dim item
for each item in request(&quot;sel1&quot;)
Response.Write item & &quot;<br>&quot;
next
%>

</BODY>
</HTML>
 
This message is based on the idea that you want to request all the selected answers for a single list box not for the entire form (which is how it appears you have it written).

guestf's answer is similar but has the answer written in line format (breaks between each selection). This solution provides all answers to be written on a single line.
-----------FORM PAGE - Test.html-------------
Code:
<form action=&quot;Test1.asp&quot; method=&quot;POST&quot; name=&quot;formname&quot;>

How did you hear about us?
<select name=&quot;listname&quot; MULTIPLE>
  <OPTION>A current/former client</OPTION>
  <OPTION>Another Site</OPTION>
  <OPTION>Friend</OPTION>
  <OPTION>Search Engine</OPTION>
  <OPTION>Traditional Print Ad</OPTION>
  <OPTION>E-Magazine/Newsletter</OPTION>
  <OPTION>Other</OPTION>
</select><br>

<input type=&quot;submit&quot; value=&quot;Submit Choices&quot;>
</form>

----------------THE RESPONSE PAGE - Test1.asp---------

Code:
You stated that you heard from us through these avenues <br>

<%=Request.Form(&quot;listname&quot;)%><br>
Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top