HTML and CSS Reference
In-Depth Information
Figure 10-18
calling the showeM() function
3. Save your changes to the file and then reload mpl.htm in your Web browser. The
link to Catherine Adler's e-mail address should once again appear in the staff
table, unchanged from what you saw earlier in Figure 10-11.
Using the function call gives the same result as the code you used earlier. However, the
great advantage is that you can reuse the showEM() function for other e-mail addresses in
the staff directory simply by changing the parameter values. You don't have to reenter all
four of the program lines. For longer programs this greatly simplifies the code.
Creating and Calling a JavaScript Function
• To create a JavaScript function that performs an action, insert the structure
functionƒ function_name ( parameters ){
ƒƒƒ JavaScriptƒcommands
}
where function_name is the name of the function, parameters is a comma-separated
list of variable names used in the function, and JavaScriptƒcommands is the set of
statements run by the function.
• To create a JavaScript function that returns a value, use
functionƒ function_name ( parameters ){
ƒƒƒ JavaScriptƒcommands
ƒƒƒreturnƒ value ;
}
where value is the value returned by the function.
• To call a JavaScript function, run the command
function_name ( values )
where function_name is the name of the JavaScript function and values is a
comma-separated list of values for the parameters of the function.
Kate asks you to call the showEM() function for the other e-mail addresses in the
staff table.
Search WWH ::




Custom Search