JavaScript
is an object-based language. And object is an items that has a defined
existence and possesses properties that describe its appearance, purpose
or behavior. Objects also have methods, which are actions that can be
performed with the object or to the object.
The Web browser itself is an object and has its own set of objects,
properties and methods, including the page, frames, forms and fields.
The browser object has a property that indicates its type (i.e. NS or
IE). You can apply different methods to the browser object, such as
open it, close it, reload the contents or move it back or forth in history.
You identify objects by their name. Some pre-defined object names include
the following:
The browser window = window
A frame = frame
History list = history
The browser being run = navigator
URL of the current page = location
Currently displayed page = document
A link on the current page = link
A target or anchor on the current page = anchor
A form on the current page = form
User defined
Objects are arranged in a document object model or DOM, which defines
the logical structure of objects and the way they are accessed and manipulated.
To reference a specific object in a script you use the object.object.object
syntax where object refers to the name of each object in relation to
its hierarchical location. For example:
window.document.formname.elementname
Most browsers assumes the presence of the window object,
so in most cases you can omit it.
Identify
object reference
Download the files
for this lab.
Open the file ordrtxt.htm. Examine the page and examine the form. Identify
the correct reference syntax for the following elements:
formdate; ccard; cname; product
Optionally you can use object collections to reference
objects as follows:
collection[i] // where i is the index
number of the item (starting with 0)
OR
collection["name"] // where
name is the name of the object
OR
collection.name // where name is the
name of the object
For example:
In the form named "order" where formdate is
the first element in the form collection:
document.order.elements[0]
document.order.elements["formdate"]
document.order.elements.formdate
Object collections include the following:
document.all
document.anchors
document.applets
document.embeds
document.form.elements
document.forms
document.frames
document.images
document.links
document.plugins
document.scripts