HTML and CSS Reference
In-Depth Information
As shown in Table 9-3, the general form of writing an object with its method is
similar to writing objects and properties.
JavaScript Methods and
Arguments
Not all JavaScript methods
require an argument. In
fact, with some methods,
if an argument is used, it
generates an error.
Table 9-3 Object and Method
General form:
objectname.method(argument values)
Comment:
where objectname is the object, method is the action, and argument values are optional items
or instructions the method should use. A period separates the object name from the method.
Examples:
window.open(Url, “”, “toolbar=no,width=500,height=400,status=no,resize=yes”)
window.alert(“This is a message”)
var ToDayDate=Date.toString( )
User-Deined Functions
A function is JavaScript code that is written to perform certain tasks repeatedly.
A user-defined function is JavaScript code written by a Web developer to perform a par-
ticular task. The function can be used whenever that task is needed, eliminating the need
to repeat the code several times throughout an application. Functions replace large sets of
JavaScript code that are too large to fit within an HTML attribute. Functions are placed
in a JavaScript section within the <head> section of the HTML code.
JavaScript objects exist in a hierarchy starting with the window object. Other objects,
such as document, navigator, and history belong to the window object. These objects are
built-in and the methods that are associated with them are often referred to as built-in
functions. These include alert(), close(), open(), and print(). These functions actually
belong to the Window object. Because the Window object is assumed, developers often
call them built-in functions. For a complete list of built-in functions, see the JavaScript
Quick Reference in Appendix G.
In this project, user-defined functions use generic container tags to display dynamic
information. A container is an HTML tag that identifies a section of HTML code using
the id attribute so content of the tag can be set or defined by the use of the innerHTML
property. The <div> tag container defines a division or section of code that groups simi-
lar elements together. To uniquely identify this <div> container, use an id attribute, with
a unique id value not used by any other tag. In this project, the id value will be used by
JavaScript to assign text to that container. Because an empty division contains no other
tags or text, it can be used to dynamically display text at a particular location within a
Web page.
Most JavaScript user-defined functions are called or invoked using event handlers.
An event is the result of an action, such as a mouse click or a Web page loading into the
browser. An event handler is JavaScript's way to associate an action with a function. In
this project, you first write the functions, and then the event handlers that will associate
the functions with specific events, such as loading the Web page.
JavaScript Help
Many Web sites provide
help for JavaScript
developers. To find
such Web sites, search
for keywords such as
“JavaScript Tutorials” or
“JavaScript Help” in any
good search engine.
Plan
Ahead
Create a <div> tag container to display a dynamic message.
To display a dynamic message on a Web page, you must:
Identify the location within the Web page where you want a dynamic message to
display. In this Web page, you determine to place the dynamic message between the
two horizontal lines beneath the banner.
Create a <div> tag container for your message.
You need to create a <div> tag
container with an id attribute, which will identify that division as separate from any
other <div> tag and act as a holding location for the message. This container, working
in conjunction with the innerHTML property, will display the dynamic message.
 
Search WWH ::




Custom Search