Brettb.Com
  HOME | ABOUT ME | BIOTECHNOLOGY | ARTICLES | GALLERY | CONTACT
Search: Go
TECHNICAL ARTICLES
 ASP
 ASP.NET
 JavaScript
 Transact SQL
 Other Articles
 Software Reviews

PHOTO GALLERIES
 Canon EOS 300D Samples
 Akihabara Maids!
 More Galleries...

TRAVEL LOG
 2009: China
 2008: Tokyo
 2007: Tokyo
 2006: Hong Kong
 2005: New York City

MORE STUFF
 Search Engine Optimisation
 Build an ASP Search Engine
 My Tropical Fishtank
 Autoglass
 SQL Month Name
 SQL Get Date Today
 SQL Year Month
 Other New Stuff...

POPULAR STUFF
 Regular Expressions
 Index Server & ASP
 JavaScript Ad Rotator

Home > Articles

Handling Multi-Select Input Boxes with ASP

The multi-select type of drop-down menu is useful if you want web site visitors to be able to select one or more items from a list.

Creating the web form

An example form is shown below:

Sample web form

To make such a web form, cut and paste the following HTML code into a page called multiselect.asp:

<P><B>Select one or more flavors from the list below</B></P>
<FORM NAME="multiselectform" METHOD="post" ACTION="multiselect.asp">
<SELECT NAME="
flavor" MULTIPLE SIZE="7">
<OPTION VALUE="
apricot">apricot</OPTION>
<OPTION VALUE="
banana">banana</OPTION>
<OPTION VALUE="
lime">lime</OPTION>
<OPTION VALUE="
orange">orange</OPTION>
<OPTION VALUE="
pineapple" >pineapple</OPTION>
<OPTION VALUE="
strawberry">strawberry</OPTION>
<OPTION VALUE="
watermelon">watermelon</OPTION>
</SELECT>
<INPUT TYPE="submit" VALUE="
Order flavor(s)" NAME="submitbutton">
</FORM>

Having done this, add some VBScript ASP code to the same page to decode the data sent to the page via POST when the form is submitted. The following ASP code snippets will enable the submitted data to be manipulated:

Extracting a list of requested flavors

Use the following code to display the flavors that were selected in the flavor
drop-down list.

<%
For a = 1 to Request.Form("flavor").Count
Response.Write("
The flavor " & Request.Form("flavor")(a) & " was selected<BR>")
Next
%>

Finding out how many flavors were selected

It is also possible to find out how many flavors were selected:

<%
Response.Write(Request.Form("flavor").Count & "
flavors were selected")
%>

Or by using a slightly more sophisticated version:

<%
If Request.Form("flavor").Count >= 1 then
Response.Write(Request.Form("flavor").Count & "
flavors were selected")
Else
Response.Write("
No flavors were selected")
End If
%>

Further Reading

  Site Map | Privacy Policy

All content is 1995 - 2012