|
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
<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
<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>
|