CD-52 Part II . JavaScript Tutorial Listing 7-1: (Apache web server)
Tuesday, July 31st, 2007CD-52 Part II . JavaScript Tutorial Listing 7-1: Calling a Function from an Event Handler
Parameters (also known as arguments) provide a mechanism for handing off a value from one statement to another by way of a function call. If no parameters occur in the function definition, both the function definition and call to the function have only empty sets of parentheses (as shown in Chapter 5, Listing 5-8). When a function receives parameters, it assigns the incoming values to the variable names specified in the function definition s parentheses. Consider the following script segment: function sayHiToFirst(a, b, c) { alert( Say hello, + a) } sayHiToFirst( Gracie , George , Harry ) sayHiToFirst( Larry , Moe , Curly ) After the function is defined in the script, the next statement calls that very function, passing three strings as parameters. The function definition automatically assigns the strings to variables a, b, and c. Therefore, before the alert()statement inside the function ever runs, aevaluates to Gracie, bevaluates to George, and c evaluates to Harry. In the alert()statement, only the a value is used and the alert reads Say hello, Gracie When the user closes the first alert, the next call to the function occurs. This time through, different values are passed to the function and assigned to a, b, and c. The alert dialog box reads Say hello, Larry Unlike other variables that you define in your script, function parameters do not use the varkeyword to initialize them. They are automatically initialized whenever the function is called.We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.