Codefixer - ASP tutorials, resources and software
ASP.NET 3.5/2.0 Hosting – Click Here
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Saturday 17 May
MembersPro PayPal - ASP Membership software

asp.netPRO “Best ASP.NET Host” – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Select Case

You can read our introductory tutorial on Select Case if you haven't done so already.

Here's an example using Select Case and a form. Below is the code for two pages, 'select.asp' and 'choice.asp'. On the first page 'select.asp' you will have the choice to select a meat type.

Once you select that meat type and click submit, the details will be posted to 'choice.asp' and your selection will determine what is displayed on 'choice.asp'. The values sent in the form select box called 'selectMeat' will be captured and assigned to a variable called TypeOfMeat in 'choice.asp', i.e. TypeOfMeat=Request.Form("selectMeat") . It's at this point we use Select Case to determine what to display depending on the value chosen, sent and received.

Select.asp

<html>
<head><title>Using Select Case</title></head>
<body>

<form name="form1" method="post" action="Choice.asp">
<select name="selectMeat">
<option value="chicken">chicken</option>
<option value="turkey">turkey</option>
<option value="ham">ham</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>

</body>
</html>

Choice.asp

<%
TypeOfMeat=Request.Form("selectMeat")

SELECT CASE TypeOfMeat
Case "chicken"
Response.write "You selected chicken."
Case "turkey"
Response.write "You selected turkey."
Case "ham"
Response.write "You selected ham."
'It's possible that none of the case statements equal the value of TypeOfMeat
'so in this scenario - use Case Else
Case Else
Response.write "There was no selection made."
END SELECT
%>

LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software