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

Example 6.5:
An if Statement Without Brackets


You don't have to use the { } brackets, but if you don't you'll get strange results:


This is the script we used: <SCRIPT LANGUAGE="JavaScript"> <!-- var sButton function function1() { if (sButton == "A") alert("You pressed button \'A\'") alert("This is the second line after the if statement") } //--> </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