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

Example 6.2:
Using = Instead of ==


Yes, we know you saw an error message when you opened this page...
That's because we replaced the == in the conditional expression with =. You'll find that the buttons still work correctly, though:


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