HOME

ASP Tutorial
ASP HOME
ASP Introduction
ASP Install
ASP Syntax
ASP Variables
ASP Procedures
ASP Forms
ASP Cookies
ASP Session
ASP Application
ASP #include
ASP Global.asa

ASP Objects
ASP Response
ASP Request
ASP Application
ASP Session
ASP Server
ASP Error

ASP FileSystem
ASP TextStream
ASP Drive
ASP File
ASP Folder
ASP Dictionary

ASP Components
ASP AdRotator
ASP BrowserCap
ASP Content Linking
ASP Content Rotator

ASP Quick Ref

Examples/Quiz
ASP Examples
ASP Quiz Test

ADO
ADO Introduction

Resources
ASP Resources
Award Winning Web Host Full Services Including Ecommerce
Please visit our sponsors !

ASP Forms and User Input

previous next

You can get form information with the Request.QueryString command and the Request.Form command.


Examples

A form that uses the "get" method
This example demonstrates how to interact with the user, with the Request.QueryString command.

A form that uses the "post" method
This example demonstrates how to interact with the user, with the Request.Form command.

A form with radio buttons
This example demonstrates how to interact with the user, through radio buttons, with the Request.Form command.


User Input

To get information from forms, you can use the Request Object.

A simple form example:

<form method="get" action="../pg.asp">
First Name:  <input type="text" name="fname"><br>
Last Name: <input type="text" name="lname"><br>
<input type="submit" value="Send">
</form>

There are two ways to get form information: The Request.QueryString command and the Request.Form command.


Request.QueryString

The Request.QueryString command collects the values in a form as text. 

Information sent from a form with the GET method is visible to everybody (in the address field). Remember that the GET method limits the amount of information to send.

If a user typed "Bill" and "Gates" in the form example above, the url sent to the server would look like this:

http://www.w3schools.com/pg.asp?fname=Bill&lname=Gates

The ASP file "pg.asp" contains the following script:

<body>
Welcome
<%
response.write(request.querystring("fname"))
response.write("&nbsp;")
response.write(request.querystring("lname"))
%>
</body>

The example above writes this into the body of a document:

Welcome Bill Gates


Request.Form

To collect the values in a form with the POST method, use the Request.Form command.

Information sent from a form with the POST method is invisible to others. The POST method has no limits, you can send a large amount of information. 

If a user typed "Bill" and "Gates" in the form example above, the url sent to the server would look like this:

http://www.w3schools.com/pg.asp

The ASP file "pg.asp" contains the following script:

<body>
Welcome
<%
response.write(request.form("fname"))
response.write("&nbsp;")
response.write(request.form("lname"))
%>
</body>

The example above writes this into the body of a document:

Welcome Bill Gates


Form Validation

The form input should be validated on the browser, by client side scripts. Browser validation has a faster response time, and reduces the load on the server.

You should consider using server validation if the input from a form is inserted into a database. A good way to validate the form on a server is to post the form into itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error.


previous next

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

IISProtect
Password Protect
Your Web Pages



Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search