Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.


Post Reply  Post Thread 

Using Variables, and Forms in Active Server Pages

Post Bank
Posting Manager
******

Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.

Signin to Remove this Post

robinson
Newbie


Posts: 18
Group: Registered
Joined: Sep 2006
Status: Offline
Reputation: 0
Points: 0 (Donate)
Post: #1

Using Variables, and Forms in Active Server Pages


Forms are a convenient way to communicate with visitors to your Web site. Using forms, you can create a survey form and ask visitors to fill it out. When they fill out the form, you can process the results automatically.

With forms, there are two steps: first you create the form, and then you process it. To create a form for an Active Server Page, just create a standard HTML form.

To try out this example, create an HTML file ("form_response.html") and cut-and-paste the following text into it.

form_response.html

Code:
<html>
<head><title>Asking for information</title></head>
<body>
<form method="post" action="form_response.asp">
Your name: <input type="text" name="name" size="20"><BR>
Your email: <input type="password" name="email" size="15"><BR>
<input type="Submit" value="Submit">
</form>
</body>
</html>


Active Server Pages provide a mechanism for processing forms that, unlike CGI scripting, doesn't involve serious programming: the Request.Form.

Considering the form above, we may create the file bellow and get a response.

form_response.asp

Code:
<html>
<head><title>Responding to a form</title></head>
<body>
Your name is <% =Request.Form("name") %> <BR>
Your email is <% =Request.Form("email") %>
</body>
</html>


To display the contents of each field in the form, type:

<% =Request.Form(fieldname) %>

where fieldname is the name of the field.

Creating a Variable
You'll probably want to do more with your forms than display their contents in a Web page. For example, based on the contents of the form, you may want to create a variable and insert that variable in different places of your response page. You may need to create a variable. To do that, just make up a name and set it equal to the contents of the field.

For example, if you have a field called "CatName" in your form, you can save it into a variable called "TheName" by typing:

<% TheName = Request.Form("CatName") %>

If you want to display "VisitorName" several times within a text you only need to include the variable in the text. For example:

My cat´s name is <% =TheName %>. Do you want to see <% =TheName %>?.
Example
The form in this example asks users to introduce their names and their favorite color: red, blue, or green. When the form is received, the server responds displaying these data.

nameandcolor.html

Code:
<html>
<head><title>Name and Color</title></head>
<body>
<FORM ACTION="nameandcolor.asp" METHOD=POST>
Let me know your Name and Favorite Color:
<P>YOUR NAME:
<INPUT TYPE="TEXT" NAME="YOURNAME" SIZE=20>
<P>COLOR:
<INPUT TYPE="RADIO" NAME="COLOR" VALUE="1" CHECKED>Red
<INPUT TYPE="RADIO" NAME="COLOR" VALUE="2">Green
<INPUT TYPE="RADIO" NAME="COLOR" VALUE="3">Blue
<P>
<INPUT TYPE="SUBMIT" VALUE="OK">
</FORM>
</body>
</html>

Now, create an ASP file ("nameandcolor.asp") and cut-and-paste the following text into it.

nameandcolor.asp
<html>
<head><title>Name and Color</title></head>
<body>
<% TheName = Request.Form("YOURNAME") %>
<% colornumber = Request.Form("COLOR") %>
Hi, <% =Thename %>.<BR>
I know your favorite color is
<% if colornumber = "1" then %>
red
<% end if %>
<% if colornumber = "2" then %>
green
<% end if %>
<% if colornumber = "3" then %>
blue
<% end if %>.
</body>
</html>

23-09-2006 01:13 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  What Are Active Server Pages? robinson 0 724 23-09-2006 12:49 AM
Last Post: robinson

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites
Rate This Thread:

Forum Jump:

Sign In to Remove Ads

Download 1000's of web templates. Unlimited access!
World's Best Web Hosting
Resources

Recommended Sites:



Visit our Sponsors!

Current time: 02-12-2008, 10:58 AM


Copyright © 2002-2008 MyBB Group
Powered By MyBB