Collection the Form Information

Home  »  ASP  »  Collection the Form Information


     The Request Object that is used to collect information from the user through Forms. The Request object has two property collections for retrieving data from the form, which are Form Collection, and the Query String Collection.

Contents

Using the Request Object

To read the values of a form field, you need to use the Request Object.

Form CollectionWhen to Use
QueryString When the form field values are being passed through the querysting, use this collection. So if you create a form with METHOD=GET, this is the Request collection you'll want to use.
Form When the form is created with its METHOD property set to POST, use this Request collection.

To use these collections, you use the following syntax:
Request.QueryString(variableName)
Request.Form(variableName)

The variableName is always the NAME property from the form field that you are interested in. For example, let's say that you created a text box in your form creation Web page with its NAME property set to Age. If , in your form processing script, you wanted to save the value of the text box into a variable name iAge, you could do so with the code below:

Example: Reading a Text Box Form Field Value Using the Request Object


To read a variable, you just need to use the correct Request collection and specity the NAME of the form field.





How text box values can be accessed in the form processing script

Retrieving Text Box values you create a text box with the <INPUT> tag. There are a number of properties you can set to alter the appearace of the text box in the form, but after the form is submitted and the data sent to the form processing script, all you care about is the NAME property. The value of the NAME property is what you use to reference the value of a particular text box.

Let's say that in the form creation web page, you create a text box with the following code.

<INPUT TYPE=TEXT NAME="PhNo">

In the form processing script, you would obtain the value of this text box with the following ASP code:



Let's look at an example form processing script that reads in a number of text box values. The first step is to create the form Web page.



TextBox.asp

Output



First Name :
Last Name :

How list box values can be accessed in the form processing script

A list box is created two HTML tags. <SELECT> and <OPTION>. For each list box, there is one opening and closing <SELECT> tag pair (<SELECT></SELECT>...). Inside the opening and closing <SELECT> tag pair, there are several <OPTION> tags. For each selectable choice in the list box, there needs to be an <OPTION> tag.

For example, if you wanted to create a list box that contained the seven days of the week, you would need seven <OPTION> tags. These tags would need to in between a pair of openining and closing <SELECT> tags. Here is the HTML that would create such a list box.







ListBox.asp


Output

Programming Tutorials


Download Complete Source Code





How check box values can be accessed in the form processing script

Check boxes are created using the <INPUT> tag with its TYPE property set to CHECKBOX. Because check box are used to group related options, all related check boxes should have identical values for their NAME properties. Related check boxes are uniquely identified from one another by their VALUE properties. When creating related check boxes, be sure give them all the same NAME but different VALUES. Reading check box values in a form processing script is slightly more complicated than reading text box or list box values. Because multiple check boxes can have the same NAME property, you don't receive one single value when you use the following:

Request(checkboxName)

When you request a group of related check boxes, you receive a comma-delimited list of the VALUES of the selected check boxes.

Imagine that you have three check boxes created with the following code:



If, in the form processing script, you had the following code:




The Completed program, Languages.html Creates a Form That Asks What Languages They Speak



ListLanguages.asp


Output



Demo - CheckBox
Please Check all of the languages that you speak.

English
French
Spanish
German
Italian


Download Complete Source Code



Unfortunately, comma-determited lists put spaces after each comma, In the preceding example, strLanguagesSpoken might equal English, French, German. Note the spaces after the commas. When split breaks up this comma-determited list into an array.







How radio box values can be accessed in the form processing script

Radio buttons are created using the <INPUT> tag with its TYPE property set to RADIO. Related radio buttons are used similarly to related check boxes. It is important that related radio buttons have the same NAME and different VALUES.

Related radio buttons are a set of radio buttons from which only one radio button can be selected. If you accepted four types of credit. you would need four related radio buttons. When the form processing script uses Request(radioButtonName), it returns the VALUE of the selected radio button option. If no option was selected, Request(radioButtonName) returns an empty string.

An Example of Using Radio Buttons



RadioButtons.asp

Output

What is your gender ?
Male
Female





Share on Google Plus
    Blogger Comment
    Facebook Comment