Product Home Page | Developer Site | Version | |
In this example an iterator is used to loop through all data values in a form request. Assume that a user fills out a form by specifying two values (Chocolate
and Butterscotch
) for the FavoriteFlavor
parameter. The following script will retrieve these values:
For Each item In Request.Form("FavoriteFlavor")
Response.Write item & "<BR>"
Next
This displays the following:
Chocolate
Butterscotch
The same output can be generated with a For...Next
loop, as shown in the following script:
For I = 1 To Request.Form("FavoriteFlavor").Count
Response.Write Request.Form("FavoriteFlavor")(I) & "<BR>"
Next
This iterator can display the parameter name, as shown in the following script.
<% For Each x In Request.Form %>
Request.Form( <%= x %> ) = <%= Request.Form(x) %> <BR>
<% Next %>
This displays the following:
FavoriteFlavor = Chocolate
FavoriteFlavor = Butterscotch
The next example uses the following form to solicit information from a user:
<FORM ACTION = "/scripts/submit.asp" METHOD = "post">
<P>Your first name: <INPUT NAME = "firstname" SIZE = 48>
<P>What is your favorite ice cream flavor: <SELECT NAME = "flavor">
<OPTION>Vanilla
<OPTION>Strawberry
<OPTION>Chocolate
<OPTION>Rocky Road</SELECT>
<p><INPUT TYPE = SUBMIT>
</FORM>
From that form, the following request body might be sent to the client:
firstname=James&flavor=Rocky+Road
The following script can then be used:
Welcome, <%= Request.Form("firstname") %>.
Your favorite flavor is <%= Request.Form("flavor") %>.
The unparsed form data is: <%= Request.Form %>
This displays the following:
"Welcome, James. Your favorite flavor is Rocky Road."
The unparsed form data is: firstname=James&flavor=Rocky+Road
Copyright © 2003 Sun Microsystems, Inc. All rights reserved.