Previous Example-|-Next Example-|-Return to Chapter Listing

Example 6.4:
Using "else"


This time, when you click on Button B something does happen, thanks to the addition of an else clause:


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