HTML and CSS Reference
In-Depth Information
<body bgcolor="lightblue">
<div align="center">
<script type="text/javascript">
<b>San Francisco</b><br />
<img src="sf.jpg" width="400" height="300" border="1">
Functions must be defined before they can be used. Therefore, functions are nor-
mally placed in a JavaScript program, between the HTML <head></head> tags. In
this example, the function is defined, but it will not do anything until it is called
from somewhere in the file.
The function keyword is followed by the user-defined name of the function called
welcome and a set of parentheses. The parentheses are used to hold parameters,
information being received by the function. What the function actually does is de-
fined in a set of statements enclosed within curly braces. The function statements
are enclosed in a set of curly braces.
2, 3
This is the code that is run whenever the function is called. It is called the func-
tion definition. When this function is called, the string San Francisco will be as-
signed to the variable called place and the alert dialog box will display “ Welcome
to San Francisco! ” in the browser window (see Figure 7.1).
This is the final closing curly brace that ends the function definition.
This is where the function is invoked or called. When the function welcome() is
called, the statements within its definition will be executed.
The function is defined in the head of the document and called from the body of
the document before the <img> tag is reached. This image will not appear until the
user clicks the OK button in the alert dialog box (see Figure 7.2).
Figure 7.1 After the function welcome() is called, output is sent to the browser.
Search WWH ::

Custom Search