|
IF statement Part2 (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 and last name.
filename=/learn/test/if2.asp
<html><head>
<TITLE>if2.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<form action="if2respond.asp" method=get>
Your First Name<INPUT NAME="FirstName" MaxLength=20><p>
Your Last Name<INPUT NAME="LastName" MaxLength=20><p>
<INPUT TYPE=submit><p><INPUT TYPE=reset>
</form></body></html>
Now we make a asp file that examines their first name and
last name after the form is submitted. As contrasted to the previous example this time we
are checking multiple conditions utilizing elseif and we are dealing with entries no
matter whether they were typed in upper or lower case.
filename=/learn/test/if2respond.asp
<html><head>
<TITLE>if2respond.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<%
fname=lcase(request.querystring("Firstname"))
lname=lcase(request.querystring("Lastname"))
If fname="george" and lname="washington" then%>
Hi.<p>You must be the first president!
<%elseIf fname="ronald" and lname="reagan" then%>
Hi.<p>You must be the actor president!
<%elseIf fname="jimmy" and lname="carter" then%>
Hi.<p>You must be the peanut farmer president!
<%elseIf fname="naoko" or fname="charles" then%>
Hi.<p>Your name reminds me of someone<p>
but I am not sure who!
<%else%>
Hi!<p>Nice to Meet You
<%end if%>
</body></html>
|