Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Forms: IF syntax #3
     [next Lesson]  Forms: For Each Iteration

If Then Part4 (by John Kauffman & Charles Carroll)

Very often you must determine what to do next based on user input. This is one of the roles of the IF statement. First we make a form that will ask a user for their first name, last name and salary.

   filename=/learn/test/if4.asp

<Test Script Below>


<html><head>
<TITLE>if4.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<form action="if4respond.asp" method=get>
Your First Name<INPUT NAME="FirstName" MaxLength="20"><p>
Your Last Name<INPUT NAME="LastName" MaxLength="20"><p>
Your Salary <INPUT NAME="Salary" MaxLength="7"><p>
<INPUT TYPE=submit><p>
</form></body></html>

This example shows how IF can deal with ranges but this example illustrates the critical factor of ordering. If you were to re-arrange these IFs they would not accurately report your salary grade.

   filename=/learn/test/if4respond.asp

<Test Script Below>


<html><head>
<TITLE>if4respond.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<%fname=request.querystring("Firstname")
lname=request.querystring("Lastname")
salary=request.querystring("Salary")
response.write "Nice to Meet You " & fname & " " & lname & "<p>"
if salary>80000 then
    salarygrade=4
end if
if salary <=80000 then
    salarygrade=3
end if
If salary <=60000 then
    salarygrade=2
end if
if salary <=40000  then
    salarygrade=1
end if
response.write ("Your Salary is $" & salary)
response.write (", your Grade is " & salarygrade & ".<p>")
%>
</body></html>

Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site