Previous Chapter's Examples-|-Next Example-|-Return to Chapter Listing

Example 6.1:
The 'if' Statement

The function1() uses an if statement to determine whether it should display a message box. It only does so if you click on button A:


This is the script we used: <SCRIPT LANGUAGE="JavaScript"> <!-- var sButton function function1() { if (sButton == "A") { alert("You pressed button \'A\'") } } //--> </SCRIPT> </HEAD> <BODY> <BR> <form> <input type="button" value=" Button A " onclick="sButton = 'A'; function1()"> <input type="button" value=" Button B " onclick="sButton = 'B'; function1()"> </form>
Previous Chapter's Examples-|-Next Example-|-Return to Chapter Listing