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 #1
     [next Lesson]  Forms: IF syntax #3

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

<Test Script Below>


<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

<Test Script Below>


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

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