Deeply Nested if. . .else Constructions : If « Language Basics « JavaScript DHTML






Deeply Nested if. . .else Constructions

   
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function testLetter(form){
    inpVal = form.entry.value; 
    if (inpVal != "") {
        if (inpVal == "A") {
            alert("Thanks for the A.");
        } else if (inpVal == "B") {
            alert("Thanks for the B.");
        } else if (inpVal == "C") {
            alert("Thanks for the C.");
        } else {          
            alert("Sorry, wrong letter or case.")
        }
    } else {   
        alert("You did not enter anything.")
    }
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
Please enter A, B, or C and press Enter key:
<INPUT TYPE="text" NAME="entry" onChange="testLetter(this.form)">
</FORM>
</BODY>
</HTML>

           
         
    
    
  








Related examples in the same category

1. Determining Whether Lowercase or Uppercase Strings Are 'More Equal' Using an If Statement
2.If statement
3.Example for If...Else statement.
4.An if..else if...else statement.
5.The else Block Responds to a false Value
6.Nested if Statements
7.Compare string and alert in dialog
8.Compare int value
9.Compare string value in if statement
10.Nested if statement, logic operator and regular expression
11.Is your input a Yes
12.Use if statement to check the value range
13.if...then...else...if
14.Nested Indented Conditional statements
15.Testing value in range