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

Example 4.5:
Why You Should Use Var


Click on the Display1 button, read the message box and close it. Then click on the Display2 button--read and close. Then click on the Display1 button again.



This is the script we used. First we created the variables and functions in the HEAD <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- var func1 = "This is the global variable named func1" function Display1() { alert(func1) } function Display2() { func1 = "This is local variable named func1" alert(func1) } //--> </SCRIPT> Then we created two buttons: <FORM> <INPUT TYPE="button" NAME="ButtonDisplay1" VALUE="Display1" onclick=Display1()><BR> <INPUT TYPE="button" NAME="ButtonDisplay2" VALUE="Display2" onclick=Display2()> <FORM>
Previous Example-|-Next Example-|-Return to Chapter Listing