ASP Tutorial
How do I use variables in ASP?
In ASP, as in other scripting languages, variables are used in many manners. A
variable is a place keeper for a piece of text, or binary code. Remember back to
your days in school where you learned about Algebra and talked about X + 1 = 2
and you knew that X =1 from your simple math. A simple single-value variable in
ASP can be use to display a single piece of text that is pre-assigned to the ASP
code, or it can be dynamically generated from a web page.
Please review the terms below. These terms will be used in this section.
| first_name = "Bob" |
|
Example of a single value
variable |
|
| |
|
|
|
| request.form("first_name") |
|
Example of a value that comes
from a form submission |
|
| |
|
|
|
rrayNames(0) = "Bob"
arrayNames(1) = "Joe"
arrayNames(2) = "Steve" |
|
a Example of an ASP array
|
|
Note: The single value variable and the
array can be any length of characters. Variables can not start with a number,
nor have a period (.) in it. The variable must have an equal sign next to it
with the value for the variable in double quotes. The variable will not need
double quotes however if the value is a field from a database. This will be
discussed later in the tutorial. Another example of a variable is below.
Create an HTML form with the lines on the left hand side below. Once it has been
created, it will look like the image beneath the script:
------------- Copy the following into form.asp -------------
<HTML>
<HEAD>
<TITLE>Variable Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="form_submit.asp" METHOD="POST">
First Name: <INPUT TYPE="TEXT" NAME="first_name">
<BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
------------- Copy the following into form_submit.asp -------------
<HTML>
<HEAD>
<TITLE>Variable Form Results</TITLE>
</HEAD>
<BODY>
Your name is
<%
first_name = request.form("first_name")
response.write first_name
%>
<BR>
</BODY>
</HTML>
Once the pages are created, upload them to your Windows 2000 server. Input your
name into the input box, and click submit. The next page will display the name
dynamically in the browser. This is your first ASP page.