This demo shows how to use an IF THEN ELSEIF statement together.
The three situations this checks for if you fill in anything, checks for the Color Blue and lastly your favorite color.. Using a ELSEIF is ok for one or two situations but nested ELSEIF statements can slow your code down. Its recommended to move to the SELECT CASE statement.
Here is the code Page 1. Simple Input form
<html><head><title></title></head><body>
<P><EM><STRONG>Type in your favorite Color and click submit</STRONG></EM></P> <FORM METHOD="post" NAME="FORM2" action="ifthen.asp"> <table> <tr><td>Favorite Color</td><td><input name="color" ></td></tr> <tr><td></td></tr> <tr><td colspan="2"><INPUT id=submit2 name=submit2 style="LEFT: 302px; TOP: 637px" type=submit value="Choose your favorite Color"></td></tr> </table> </FORM>
</BODY> </HTML>
Here is page 2 Results Page
<%@ Language=VBScript %> <%
dim strColor
If request("color") = "" Then strColor = "You didn't fill anything in" Elseif request("color") = "Blue" Then strColor = "Your Favorite Color :" & request("color") Else strColor = "Your Favorite Color is: " & request("Color") End If %> <HTML> <HEAD> </HEAD> <BODY> <% = strColor %> </BODY> </HTML>