Open In App

ASP Request.Form Collection

The Request.Form Collection in ASP is used for returning the collection of form elements that posted to the HTTP request body, with a form using the POST method. 

Syntax



Request.Form( element )[(index)|.Count]

Parameter:

Example 1: Below code uses the for loop to access the form values filled by the user. We could retrieve those values like this: 






<% 
for i=1 to Request.Form("color").Count
 Response.Write(Request.Form("color")(i) & "<br>")
next
%>

Output: 

Blue
Green

Example 2: 




<form action="submit.asp" method="post">
    <p>First name: <input name="firstname"></p>
    <p>Last name: <input name="lastname"></p>
  
    Your favorite game:
    <select name="game">
    <option>Hockey</option>
    <option>Cricket</option>
    <option>FootBall</option>
    <option>Golf</option>
    <option>Basket Ball</option>
</select>
  
<p><input type="submit"></p>
</form>

Following Values filled by the user:

firstname=naman&lastname=jain&game=cricket

Here is the ASP code that is used to retrieve the information from the form. 




Hello <%=Request.Form("firstname")%>.  
Your favorite game is <%=Request.Form("game")%>.

Output

Hi, Naman. Your favorite game is Cricket

Article Tags :