10 year anniversary

Home


Hosting Directory


Host Search


Request a Quote


Web Hosting News


Hosting Forums


Web Host Awards


Guides
Web Hosting
Choose a Host
Dedicated Servers
Reselling
Free Hosting
Articles
Industry News
HTML Explained
Advanced HTML
ASP Explained


Free Listings on Web Host Directory and drive buyers to your Web Hosting Business





ASP Explorer Back to Articles & Guides 
ASP Training - Looping and Form Handling

By this point you are should have a fair grasp of what active server pages involve, be able to recognise an asp page when you see one (by the .asp extension on the URL or by the <% if access to the source code on the web server).

This page will be concerned with processing HTML forms using ASP. I will also start to introduce you to some of the "looping" mechanisms that come with ASP to make your life easier.
(We will use loops quite a lot in the later pages when dealing with updating and displaying information from a database.)

Warning

This is an ASP guide. Whilst some elements of HTML form use will be touched upon and we will use HTML form elements this is not going to be an HTML form trainer; I am going to assume you have sufficient HTML form knowledge to cope; or that you are clever enough to work out what is going on by viewing the HTML source of this page. If neither of these statements fit you then now would be a good time to surf the web for some more information; there are loads of web sites that are available to help you learn HTML.

Example Form

Fill in your name, pick an option and click a button to see ASP form handling in action.
Your Name Is? :

Pick an option :

Submit the form using one of the buttons below :




Not very exciting is it? But this is a training guide so what did you expect?  Anyhow,  let's have a look at how this ASP is working. First take a look at the HTML source, then look at the ASP to see how it is processed. The HTML The following is an excerpt from the HTML to display the form and not the whole HTML page itself.
<form action="scripts/processExampleForm.asp" method="post">
Your Name Is? : <input type="text" name="name" size="20">
<br>
Pick an option : 
<select name="exampleSelection">
	<option selected>One
	<option>Two
	<option>Three
	<option>Four
</select>
<br>
Submit the form using one of the buttons below :
<br>
<input type="submit" name="submitButton" value="Btn One">
<input type="submit" name="submitButton" value="Btn Two">
<input type="submit" name="submitButton" value="Btn Three">
</form>


This is a fairly simple form. There is a free text box to enter your name; a pick list to select a number and three submit buttons, with different values for each button. This information is passed to the ASP script identified in the <form...> section, specifically the "action" attribute of the form tag.

The ASP

<% 
 name = request.form("name")
 optionSelected = request.form("exampleSelection")
 whichButton = request.form("submitButton")
%>
<html>
<body>
Hello <%= name %>,
you selected <%= optionSelected %>
and submitted the form using <%= whichButton %>

</body>
</html>
Looking through this script you ought to be able to pick out what is happening fairly easily. The first ASP section gets the information from the form and stores this in three variables name, optionSelected, whichButton ; this information is then output to an html page, exactly as was explained in ASP Training : The Basics. So, lets take a closer look at the first three lines then.

As well as being a scripting (programming) language, ASP/VBScript comes with a number of objects to allow you to access information easily and in a consistent manner (we will meet more of these later when we look at the database component).

One of the standard objects provided is the request object; the request object allows you to request information from the browser and the web server. In the case of request.form you are requesting information about the data being passed from the form; you can also use request to access information stored in cookies, the query string and server variables (if all this means nothing to you, don't worry, we will only be thinking about the .form parts of the request object).

To get access to the values being passed by the HTML form, you plug in the name of the HTML form element that you want to get hold of. So in our HTML form, we created a name form element, an exampleSelection form element and a submitButton form element.

It is as simple as that, to get the value of an HTML form element into your ASP script, you just use the request.form object and put the name of the form element into the brackets, so that you end up with
<% 
 name = request.form("name")
 optionSelected = request.form("exampleSelection")
 whichButton = request.form("submitButton")
%>
And now we have the variables name, optionSelected and whichButton in our ASP script ready to be used in any way we see fit.

Simple.

As this guide continues you will see more complex manipulation of form elements that just echo'ing them back to the page; but suffice for now that you know how to get hold of the form information and store it in variables for you to use at a later date.

Warning

A very common mistake when working with ASP and HTML forms is to forget the METHOD attribute. If you forget to put method="post" in your HTML form then the request.form will not work (there is a related programmers note before the summary on the next page).


ASP Training - Looping and Form Handling Part 2 >>

ASP Training - The Basics Table of Contents

Featured Hosts
IX Web Hosting.com: As low as $0.81/mo per hosted domain name! FREE Domain Registration, 200,000MB to UNLIMITED Web Space & FREE Website Builder!
SuperbHosting.Net: Starting as low as $2.50/m, 2 FREE Domains, FREE Setup + WebSiteCreator + Blog Software, Unlimited Traffic, 200 GB HD, your own IP, 2500 Emails, daily backups & more, connected to our coast-to-coast backbone.
$5.95/mo – 6 MONTHS FREE: UNLIMITED Disk Space, UNLIMITED Bandwidth, FREE Domain, FREE Site Builder, FREE Setup, and MORE!
Crystaltech.com: Host with the best! 3 FREE months with a waived setup on any new dedicated server! Call 1-877-323-HOST or visit CrystalTech.com today!
Hivelocity.com: Core2Duo- $119/mo, Core2Quad- $149/mo, Quad-Core Xeon- $185/mo, Dual Quad-Core Xeon- $299/mo, Zero Setup- Free Ram Upgrades
Ace-host.net: 500 GB Disk Space, 5,000 GB Bandwidth, Host up to 20 Domains, Unlimited Email Addresses, 24/7 Technical Support, 99.9% Uptime Guarantee, 30-Day Money Back Guarantee - Starting at $6.95/month
Rackspace: Rackspace delivers fully managed windows and linux hosting solutions, a Zero-Downtime Network(tm) and 24x7x365 Fanatical Support(tm).
Aplus.Net: AWARD-WINNING Hosting at Small Business-Friendly Prices (from $5.95 / mo.) - FREE Setup - FREE Domain - 99.9% Uptime - 24/7 Support - LIMITED TIME SALE!
hostgator.com: CALL NOW 1-866-96-GATOR >> 24/7 >>PHONE AND INSTANT MESSENGER SUPPORT >>A TON OF SPACE!! >>> TONS OF >>BANDWIDTH! >> FREE SETUP >> DOZENS OF FREE SCRIPTS INSTALLED >>
Softlayer Technologies: Dedicated Servers, free services & private network; Come to SoftLayer for best in class facilities, technology & customer support
WebIntellects: Tired of bait and switch hosting? Low cost gimmicks? So are we. See why we are the provider of choice in over 80 countries world-wide!
The Planet Hosting: Dedicated Server Deals: As the leading dedicated server hosting provider, The Planet always gives you the best prices on website hosting. See all our deals.
US2.net: Offers customers another choice in hosting. Our complete and Plus web hosting packages are generous in specification, with a range of essential features, but best of all at an amazing price.

Most Popular Web Hosting Searches Advertisers, Get Listed Here. 
Gogax Hosting
Gogax offers you an ALL Inclusive Premium web hosting package. INSTANT & FREE Setup. 24/7 Customer Support, MANY hosting features ... more
LYPHA.COM - Recommended
2.5TB Storage, 20TB Transfer - $3.95/mo. Free Domain Name.... more
Mochahost.com
From $3.71/mo; cPanel, Unlimited mailboxes, Free Site Builder w/ 500+ templates, PHP5, MySQL5, JSP, Ruby, SVN, 20,000 MB space & ... more



Unix/Linux Shared Hosts
Gogax Hosting
Gogax offers you an ALL Inclusive Premium web hosting ... more
LYPHA.COM - Recommended
2.5TB Storage, 20TB Transfer - $3.95/mo. Free Domain Name.... more
OKmyhosting
Offer affordable web hosting packages.5G storage and 50G ... more
Unix/Linux Dedicated Hosts
Gogax Hosting
Order Today! Servers in 60 seconds, FREE Setup, INSTANT ... more
Versaweb Hosting
Get the dedicated hosting solution you need, starting as ... more
Peer1 Network
Boost your performance online with PEER 1's award-winning ... more
Top 3 Shared Hosts
Gogax Hosting
Gogax offers you an ALL Inclusive Premium web hosting ... more
LYPHA.COM - Recommended
2.5TB Storage, 20TB Transfer - $3.95/mo. Free Domain Name.... more
IX-ONE.COM Domain Company
IX-ONE.COM is a provider of world-class products at ... more
advertisers: Get listed here
> About us
> Terms & Conditions
> Privacy Policy
> Advertising
> Contact us
> Forum Archive
> Sitemap
> RSS  RSS
RECOMMENDED BY
  Copyright © 1997-2008, Web Host Directory Ltd.  Web Hosting Directory