HTML and CSS Reference
In-Depth Information
To insert the showEM() function:
1. Return to the mpl.htm file in your text editor.
2. Directly above the closing </head> tag, insert the following script element and
function, as shown in Figure 10-16:
<scriptƒtype=”text/javascript”>
ƒƒƒfunctionƒshowEM(userName,emServer)ƒ{
ƒƒƒƒƒƒvarƒemLinkƒ=ƒuserNameƒ+ƒ“@”ƒ+ƒemServer;
ƒƒƒƒƒƒdocument.write(“<aƒhref= ' mailto:”ƒ+ƒemLinkƒ+ƒ“ ' >”);
ƒƒƒƒƒƒdocument.write(emLink);
ƒƒƒƒƒƒdocument.write(“</a>”);
ƒƒƒ}
</script>
Figure 10-16
inserting the showeM() function
Calling a Function
When a browser encounters a function, it bypasses it without executing any of the
code contained within the function. The code is executed only when called by another
JavaScript command. If the function has any parameters, the initial values of the param-
eters are set when the function is called. The expression to call a function and run the
commands it contains has the form
function_name (parameterƒvalues)
where function_name is the name of the function and parameterƒvalues is a comma-
separated list of values that match the parameters of the function. For example, to call
the showMsg() function described earlier using the text string Monroe Public Library as
the value of the libName parameter, you would run the command
showMsg(“MonroeƒPublicƒLibrary”);
resulting in the following HTML code being written to the document (see Figure 10-17):
<p>WelcomeƒtoƒtheƒMonroeƒPublicƒLibrary</p>
 
Search WWH ::




Custom Search