Skip to main content.

Web Based Programming Tutorials

Homepage | Forum - Join the forum to discuss anything related to programming! | Programming Resources

Special Edition Using Java Script

Appendix B -- JavaScript Glossary

Appendix B

JavaScript Glossary


CONTENTS

This appendix is an expanded discussion of JavaScript's language elements. This enhanced glossary not only defines common terms or lingo associated with JavaScript, but also lists the objects, methods, properties, and event handlers that make JavaScript such a growing, powerful language.

Terms

While not necessarily JavaScript objects or keywords, the following definitions can help in your understanding of JavaScript and how it works. These are the general terms that are used in most discussions about JavaScript and its implementation.

Cookie  A special object containing state/status information about the client that can be accessed by the server. Included in that state object is a description of the range of URLs for which that state is valid. Future HTTP requests from the client falling within a range of URLs described within the state object will include transmission of the current value of the state object from the client back to the server.

This simple form of data storage allows the server to provide "personalized" service to the client. Online merchants can store information about items currently in an "electronic shopping basket," services can post registration information and automate functions such as typing a user-ID, and user preferences can be saved on the client and retrieved by the server when the site is contacted. For limited-use information, such as shopping services, it is also possible to set a time limit on the life of the cookie information.

CGI scripts are typically used to set and retrieve cookie values. To generate the cookie requires sending an HTTP header in the following format:

Set-Cookie: NAME=Value; [EXPIRES=date;] [PATH=pathname;]  [DOMAIN=domainname;] [SECURE]

When a request for cookie information is made, the list of cookie information is searched for all URLs that match the current URL. Any matches are returned in this format:

cookie: NAME1=string1; NAME2=string2; ...

Cookie was an arbitrarily assigned name. For more information about the cookie and its function, see http://home.netscape.com/newsref/std/cookie_spec.html.

Event Handler  Attributes of HTML tags embedded in documents. The attribute assigns a JavaScript command or function to execute when the event happens.

Function  A user-defined or built-in set of statements that perform a task. It can also return a value when used with the return statement.

Hierarchy  Navigator objects exist in a set relation to each other that reflects the structure of an HTML page. This is referred to as instance hierarchy because it only works with specific instances of objects, rather than general classes.

The window object is the parent of all other Navigator objects. Underneath window, location, history, and document all share precedence. Document includes forms, links, and anchors.

Each object is a descendant of the higher object. A form called orderForm is an object, but is also a property of document. As such, it is referred to as document.orderForm.

Java  An object-oriented, platform-independent programming language developed by Sun Microsystems and used to add additional functionality to Web pages. Programming in Java requires a Java Development Kit with compiler and core classes.

JavaScript  A scripting language developed by Netscape for HTML documents. Scripts are performed after specific user-triggered events. Creating JavaScript Web documents requires a text editor and compatible browser.

Literal  An absolute value not assigned to a variable. Examples include 1, 3.1415927, "Bob", true.

Method  A function assigned to an object. For example, bigString.toUpperCase() returns an uppercase version of the string contained in bigString.

Object  A construct with properties that are JavaScript variables or other objects. Functions associated with an object are known as the object's methods. You access the properties of an object with a simple notation:

objectName.propertyName

Both object and property names are case-sensitive.

Operator  Performs a function on one or more operands or variables. Operators are divided into two classes: binary and unary. Binary operators need two operands, and unary operands can operate on a single operand.

For example, addition is a binary operand:

sum = 1 + 1

Unary operands are often used to update counters. The following example increases the variable by 1:

counter++

See appendix C, "JavaScript Commands and Grammar," for a list of operators and their precedence.

Property  Used to describe an object. A property is defined by assigning it a value. There are several properties in JavaScript that contain constants: values that never change.

Script  One or more JavaScript commands enclosed with a <SCRIPT> tag.

Objects

JavaScript is an object-oriented language, so at its heart is a predefined set of objects which relate to the various components of an HTML page and their relation to each other. To view or manipulate the state of an object requires the use of properties and methods, which are also covered in this appendix. If an object is also used as a property of another object, that relationship is listed following the definition. Related properties, methods, and event handlers for each object are listed following the definition.

anchors  A piece of text that can be the target of a hypertext link. This is a read-only object which is set in HTML with <A> tags. To determine how many anchors are included in a document, use the length property.

document.anchors.length

Unless the anchor name is an integer, the value of document.anchor[index] will return null.

Property of document. See link object; see anchor method.

button  An object that is a form element and must be defined within a <FORM> tag and can be used to perform an action.

Property of form. See objects reset and submit; see properties name and value; see click method; see onClick event handler.

checkbox  A form element that the user sets to on or off by clicking and that must be defined in a <FORM> tag. Using the checkbox object, you can see if the box is checked and review the name and value.

Property of form. See radio object; see properties checked, defaultChecked, name, value; see click method; see onClick event handler.

Date  Replaces a normal date type. Although it does not have any properties, it is equipped with a wide range of methods. In its current release, Date does not work with dates prior to 1/1/70.

Methods for getting and setting time and date information are divided into four classes: set, get, to, and parse/UTC.

Except for the date, all numerical representation of date components begin with zero. This should not present a problem except with months, which are represented by zero (January) through 11 (December).

The standard date syntax is "Thu, 11 Jan 1996 06:20:00 GMT". U.S. time zone abbreviations are also understood; but for universal use, specify the time zone offset. For example, "Thu, 11 Jan 1996 06:20:00 GMT+0530" is a place five hours and 30 minutes west of the Greenwich meridian.

See methods getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getYear, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toLocaleString, toString.

document  An object created by Navigator when a page is loaded, containing information on the current document, such as title, background color, and forms. These properties are defined within <BODY> tags. It also provides methods for displaying HTML text to the user.

You can reference the anchors, forms, and links of a document by using the anchors, forms, and links arrays of the document object. These arrays contain an entry for each anchor, form, or link in a document.

Property of window. See frame object; see properties alinkColor, anchors, bgColor, cookie, fgColor, forms, lastModified, linkColor, links, location, referrer, title, vlinkColor; see methods clear, close, open, write, writeln; see event handlers onLoad and onUnload.

elements  An array of form elements in source order, including buttons, checkboxes, radio buttons, text, and textarea objects. The elements can be referred to by their index:

formName.elements[index]

Elements can also be referenced by the element name. For example, a password element called newPassword is the second form element on an HTML page. Its value is accessed in three ways:

formName.elements[1].value
formName.elements["newPassword"].value
formName.newPassword.value

Values cannot be set or changed using the read-only elements array.

Property of form. See length property.

form  A property of the document object. Each form in a document is a separate and distinct object that can be referenced using the form object. The form object is an array created as forms are defined through HTML tags. If the first form in a document is named orderForm, then it could be referenced as document.orderForm or document.forms[0].

Property of document. See hidden object; see properties action, elements, encoding, forms, method, name, target; see submit method; see onSubmit event handler.

frame  A window that contains HTML sub-documents that are independently scrollable. Frames can point to different URLs and be targeted by other frames-all in the same window. Each frame is a window object defined using the <FRAMESET> tag to define the layout that makes up the page. The page is defined from a parent HTML document. All sub-documents are children of the parent.

If a frame contains definitions for SRC and NAME attributes, then the frame can be identified from a sibling by using the parent object as parent.frameName or parent.frames[index].

Property of window. See objects document and window; see properties defaultStatus, frames, parent, self, status, top, window; see methods setTimeout and clearTimeout.

hidden  A text object suppressed from appearing on an HTML form. Hidden objects can be used in addition to cookies to pass name/value pairs for client-server communication.

Property of form. See properties cookie, defaultValue, name, value.

history  This object is derived from the Go menu and contains URL link information for previously visited pages.

Property of document. See location object; see length property; see methods back, forward, go.

link  A location object. In addition to providing information about existing hypertext links, the link object can also be used to define new links.

Property of document. See anchor object; see properties hash, host, hostname, href, length, pathname, port, protocol, search, target; see link method; see event handlers onClick and onMouseOver.

location  Contains complete URL information for the current document, while each property of location contains a different portion of the URL.

Property of document. See history object; see properties hash, host, hostname, href, location, pathname, port, protocol, search, target.

Math  Includes properties for Mathematical constants and methods for functions. For example, to access the value of pi in an equation, use:

Math.PI

Standard trigonometric, logarithmic, and exponential functions are also included. All arguments in trigonometric functions use radians.

See properties E, LN10, LN2, PI, SQRT1_2, SQRT2; see methods abs, acos, asin, atan, ceil, cos, exp, floor, log, max, min, pow, random, round, sin, sqrt, tan.

navigator  Contains information on the current version of Navigator used by the client.

See objects link and anchors; see properties appName, appCodeName, appVersion, userAgent.

password  Created by HTML password text fields and masked when entered by the user. It must be defined with an HTML <FORM> tag.

Property of form. See text object; see properties defaultValue, name, value; see methods focus, blur, select.

radio  Objects created within HTML <FORM> tags and representing radio buttons. A set of radio buttons enables the user to select one item from a list. When it is created, it takes the form of document.formName.radioName[index], where the index is a number representing each button beginning with zero.

Property of form. See objects checkbox, select; see properties checked, defaultChecked, index, length, name, value; see click method; see onClick event handler.

reset  Correlates with an HTML reset button, which resets all form objects to their default values. A reset object must be created within a <FORM> tag.

Property of form. See objects button and submit; see properties name and value; see click method; see onClick event handler.

select  A selection list or scrolling list on an HTML form. A selection list enables the user to choose one item from a list, while a scrolling list enables the choice of one or more items from a list.

Property of form. See radio object; see properties length, name, options, selectedIndex; see methods blur and focus; see event handlers onBlur, onChange, onFocus.

For the options property of select, see defaultSelected, index, selected, text, value.

string  A series of characters defined by double or single quotes. For example:

myDog = "Brittany Spaniel"

returns a string object called myDog with the value "Brittany Spaniel". Quotation marks are not a part of the string's value-they are only used to delimit the string. The object's value is manipulated using methods that return a variation on the string; for example myDog.toUpperCase() returns "BRITTANY SPANIEL". It also includes methods that return HTML versions of the string, such as bold and italics.

See objects text and textarea; see length property; see methods anchor, big, blink, bold, charAt, fixed, fontcolor, fontsize, indexOf, italics, lastIndexOf, link, small, strike, sub, substring, sup, toLowerCase, toUpperCase.

submit  Causes the form to be submitted to the program specified by the action property. It is created within an HTML <FORM> tag. It always loads a new page, which may be the same as the current page if an action isn't specified.

Property of form. See objects button and reset; see properties name and value; see click method; see onClick event handler.

text  A one-line input field on an HTML form that accepts characters or numbers. Text objects can be updated by assigning new contents to its value.

Property of form. See objects password, string, textarea; see properties defaultValue, name, value; see methods focus, blur, select; see event handlers onBlur, onChange, onFocus, onSelect.

textarea  Similar to a text object, with the addition of multiple lines. A textarea object can also be updated by assigning new contents to its value.

Property of form. See objects password, string, text; see properties defaultValue, name, value; see methods focus, blur, select; see event handlers onBlur, onChange, onFocus, onSelect.

window  Created by Navigator when a page is loaded containing properties that apply to the whole window. It is the top-level object for each document, location, and history object. Because its existence is assumed, you do not have to reference the name of the window when referring to its objects, properties, or methods. For example, the following two lines have the same result (printing a message to the status line):

status("Go away from here.")
window.status("Go away from here.")

A new window is created using the open method:

aNewWindow = window.open("URL","Window_Name",["windowFeatures"])

The variable name is used to refer to the window's properties and methods. The window name is used in the target argument of a form or anchor tag.

See objects document and frame; see properties defaultStatus, frames, parent, self, status, top, window; see methods alert, close, confirm, open, prompt, setTimeout, clearTimeout; see event handlers onLoad and onUnload.

Properties

Properties are used to view or set the values of objects. An object is simply a vague generality until a property is used to define the values that make it specific.

action  The action property is a reflection of the action attribute in an HTML <FORM> tag, consisting of a destination URL for the submitted data. This value can be set or changed before or after the document has been loaded and formatted.

In this example, the action for a form called outlineForm is set to the URL contained in the variable outlineURL.

outlineForm.action=outlineURL

Property of form. See properties encoding, method, target.

alinkColor  The color of a link after the mouse button is pressed-but before it's released-and expressed as a hexadecimal RGB triplet or string literal. It cannot be changed after the HTML source is processed. Both of these examples set the color to alice blue:

document.alinkColor="aliceblue"
document.alinkColor="F0F8FF"

Property of document. See properties bgColor, fgColor, linkColor, vlinkColor.

anchors  An array of all defined anchors in the current document. If the length of an anchor array in a document is 5, then the anchors array is represented as document.anchors[0] through document.anchors[4].

Property of document. See anchor object; see properties length and links.

appCodeName  Returns a read-only string with the code name of the browser.

document.write("The code name of your browser is " +  navigator.appCodeName)

For most Netscape Navigator 2.0 users, this returns:

The code name of your browser is Mozilla

Property of navigator. See properties appName, appVersion, userAgent.

appName  Returns a read-only string with the name of the browser.

Property of navigator. See properties appCodeName, appVersion, userAgent.

appVersion  Returns a string with the version information of the browser in the format "releaseNumber (platform; country)". For a release of Netscape 2.0,

document.write(navigator.appVersion)

returns

2.0 (Win95; I)

This specifies Navigator 2.0 running on Windows 95 with an international release. The U country code specifies a U.S. release, while an I indicates an international release.

Property of navigator. See properties appName, appCodeName, userAgent.

bgColor  The document background color expressed as a hexadecimal RGB triplet or string literal. It can be reset at any time. Both of these examples set the background to alice blue:

document.bgColor = "aliceblue"
document.bgColor = "F0F8FF"

Property of document. See properties alinkColor, fgColor, linkColor, vlinkColor.

checked  A Boolean value (true or false), indicating whether a checkbox or radio button is selected. The value is updated immediately when an item is checked. It's used in the following form:

formName.checkboxName.checked
formName.radioButtonName[index].checked

Property of checkbox and radio. See defaultChecked property.

cookie  String value of a small piece of information stored by Navigator in a client-side cookies.txt file. The value stored in the cookie is found using substring charAt, IndexOf, and lastIndexOf.

For more information, see the discussion in the "Terms" section.

Property of document. See hidden object.

defaultChecked  A Boolean value (true or false) indicating whether a checkbox or radio button is checked by default. Setting a value to defaultChecked can override the checked attribute of a form element. The following section of code will reset a group of radio buttons to its original state by finding and setting the default button:

for (var i in menuForm.choices) {
if (menuForm.choices[i].defaultChecked) {
menuForm.choice[i].defaultChecked = true
}
}

Property of checkbox and radio. See form object; see checked property.

defaultSelected   A Boolean value (true or false) representing the default state of an item in a form select element. Setting a value with this property can override the selected attribute of an <OPTION> tag. The syntax is identical to defaultChecked.

Property of options. See properties index, selected, selectedIndex.

defaultStatus  The default message displayed in the status bar at the bottom of a Navigator window when nothing else is displayed. This is preempted by a priority or transient message, such as a mouseOver event with an anchor. For example,

window.defaultStatus = "Welcome to my home page"

displays the welcome message while the mouse is not over a link, or Netscape is not performing an action that it needs to notify the user about.

Property of window. See status property.

defaultValue  The initial contents of hidden, password, text, textarea, and string form elements. For password elements, it is initially set to null for security reasons, regardless of any set value.

Property of hidden, password, text, textarea. See value property.

E  The base of natural logarithms, also known as Euler's constant. The value is approximately 2.718.

Property of Math. See properties LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2.

elements  An array of objects containing form elements in HTML source order. The array index begins with zero and ends with the number of form elements -1.

Property of form. See elements object.

encoding  Returns a string reflecting the MIME encoding type, which is set in the enctype attribute of an HTML <FORM> tag.

Property of form. See properties action, method, target.

fgColor  The color of foreground text represented as a hexadecimal RGB triplet or a string literal. This value cannot be changed after a document is processed. It can take two forms:

document.fgColor="aliceblue"
document.fgColor="F0F8FF"

Property of document. See properties alinkColor, bgColor, linkColor, vlinkColor; see fontcolor method.

forms  An array of objects corresponding to named forms in HTML source order and containing an entry for each form object in a document.

Property of document. See form object; see length property.

frames  An array of objects corresponding to child frame windows created using the <FRAMESET> tag. To obtain the number of child frames in a window, use the length property.

Property of window. See frame object; see length property.

hash  Returns a string with the portion of a URL beginning with a hash mark (#), which denotes an anchor name fragment. It can be used to set a hash property, although it is safest to set the entire URL as an href property. An error is returned if the hash isn't found in the current location.

Property of link and location. See anchor object; see properties host, hostname, href, pathname, port, protocol, search properties.

host  Returns a string formed by combining the hostname and port properties of a URL, and provides a method for changing it.

location.host = "www.montna.com:80"

Property of link and location. See properties hash, hostname, href, pathname, port, protocol, search.

hostname  Returns or changes a string with the domain name or IP address of a URL.

Property of link and location. See properties hash, host, href, pathname, port, protocol, search.

href  Returns a string with the entire URL. All other location and link properties are substrings of href, which can be changed at any time.

Property of link and location. See properties hash, host, hostname, pathname, port, protocol, search.

index  Returns the index of an option in a select element with zero being the first item.

Property of options. See properties defaultSelected, selected, selectedIndex.

lastModified  A read-only string containing the date that the current document was last changed, based on the file attributes. The string is formatted in the standard form used by JavaScript (see Date object). A common usage is:

document.write("This page last modified on " + document.lastModified)

Property of document.

length  An integer reflecting a length- or size-related property of an object.

ObjectProperty Measured
historyLength of the history list
stringInteger length of the string; zero for a null string
radioNumber of radio buttons
anchors, forms, frames, links, options Number of elements in the array

Property of anchors, elements, forms, frame, frames, history, links, options, radio, string, window.

linkColor  The hyperlink color displayed in the document, expressed as a hexadecimal RGB triplet or as a string literal. It corresponds to the link attribute in the HTML <BODY> tag, and cannot be changed after the document is processed.

Property of document. See properties alinkColor, bgColor, fgColor, vlinkColor.

links  An array representing link objects defined in HTML using <A HREF=URL> tags with the first link identified as document.links[0].

See link object. See properties anchors and length.

LN2  A constant representing the natural logarithm of 2 (approximately 0.693).

Property of Math. See properties E, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2.

LN10  A constant representing the natural logarithm of 10 (approximately 2.302).

Property of Math. See properties E, LN2, LOG2E, LOG10E, PI, SQRT1_2, SQRT2.

location  Returns a string with the URL of the current document. This read-only property (document.location) is different from the location objects properties (window.location.propertyName), which can be changed.

Property of document. See location object.

LOG2E  A constant representing the base 2 logarithm of e (approximately 1.442).

Property of Math. See properties E, LN2, LN10, LOG10E, PI, SQRT1_2, SQRT2.

LOG10E  A constant representing the base 10 logarithm of e (approximately .434).

Property of Math. See properties E, LN2, LN10, LOG2E, SQRT1_2, SQRT2.

method  Reflects the method attribute of an HTML <FORM> tag: either <GET> or <POST>. It can be set at any time. The first function returns the current value of the form object, while the second function sets the method to the contents of newMethod.

function getMethod(formObj) {
return formObj.method
}
function setMethod(formObj,newMethod) {
formObj.method = newMethod
}

Property of form. See properties action, encoding, target.

name  Returns a string with the name attribute of the object. This is the internal name for button, reset and submit objects, not the on-screen label.

For example, after opening a new window with indexOutline = window.open("http://www.wossamatta.com/outline.html","MenuPage") and issuing the command document.write(indexOutline.name), JavaScript returns "MenuPage", which was specified as the name attribute.

Property of button, checkbox, frame, password, radio, reset, select, submit, text, textarea, window. See value property.

options  An array of option objects created by a select form element. The first option's index is zero, the second is 1, and so on.

See select object.

parent  Refers to the calling document in the current frame created by a <FRAMESET> tag. Using parent allows access to other frames created by the same <FRAMESET> tag. For example, two frames invoked are called "index" and "contents." The "index" frame can write to the "contents" frame using the syntax:

parent.contents.document.write("Kilroy was here.")

Property of frame and window.

pathname  Returns the path portion from a URL. Although the pathname can be changed at any time, it is always safer to change the entire URL at once using the href property.

Property of link and location. See properties hash, host, hostname, href, port, protocol, search.

PI  Returns the value of pi (approximately 3.1415927). This is the ratio of the circumference of a circle to its diameter.

Property of Math. See properties E, LN2, LN10, LOG2E, LOG10E, SQRT1_2, SQRT2.

port  Returns the port number of a URL address, which is a substring of the host property in href.

Property of link and location. See properties hash, host, hostname, href, pathname, protocol, search.

protocol  Returns a string with the initial portion of the URL, up to and including the colon, which indicates the access method (http, ftp, mailto, etc.).

Property of link and location. See properties hash, host, hostname, href, pathname, port, search.

referrer   Returns a read-only URL of the document that called the current document. In conjunction with a CGI script, it can be used to keep track of how users are linked to a page.

document.write("You came here from a page at " + document.referrer)

Property of document.

search  Returns a string containing any query information appended to a URL.

Property of link and location. See properties hash, host, hostname, href, pathname, port, protocol.

selected  Returns a Boolean value (true or false) indicating the current state of an option in a select object. The selected property can be changed at any time, and the display will immediately update to reflect the new value. The selected property is useful for select elements that are created using the multiple attribute. Using this property, you can view or change the value of any element in an options array without changing the value of any other element in the array.

Property of options. See properties defaultSelected, index, selectedIndex.

selectedIndex  Returns an integer specifying the index of a selected item. The selectedIndex property is useful for select elements that are created without using the multiple attribute. If selectedIndex is evaluated when the multiple option is selected, the property returns the index of the first option only. Setting the property clears any other options that are selected in the element.

Property of select, options. See properties defaultSelected, index, selected.

self  Refers to the current window or form, and is useful for removing ambiguity when dealing with window and form properties with the same name.

Property of frame and window. See window property.

SQRT1_2  The square root of 1/2, also expressed as the inverse of the square root of 2 (approximately 0.707).

Property of Math. See properties E, LN2, LN10, LOG2E, LOG10E, PI, SQRT2.

SQRT2  The square root of 2 (approximately 1.414).

Property of Math. See properties E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2.

status  Specifies a priority or transient message to display in the status bar at the bottom of the window, usually triggered by a mouseOver event from an anchor. To display when the mouse pointer is placed over a link, the usage is:

<A anchor definition onMouseOver="window.dstatus='Your message.';  return true">link</A>

Note the use of nested quotes and the required return true required for operation.

Property of window. See defaultStatus property.

target  A string specifying the name of a window for responses to be posted to after a form is submitted. For a link, target returns a string specifying the name of the window that displays the content of a selected hypertext link.

homePage.target = "http://www.wossamatta.com/"

A literal must be used to set the target property. JavaScript expressions and variables are invalid entries.

Property of form, link, location. See properties action, encoding, method.

text  Returns the value of text following the <OPTION> tag in a select object. It can also be used to change the value of the option, with an important limitation-while the value is changed, its appearance on-screen is not.

Property of options.

title  Returns the read-only value set within HTML <TITLE> tags. If a document doesn't include a title, the value is null.

Property of document.

top  The topmost window, called an ancestor or Web browser window, that contains frames or nested framesets.

Property of window.

userAgent  Header sent as part of HTTP protocol from client to server to identify the type of client. The syntax of the returned value is the same as appVersion.

Property of navigator. See properties appName, appVersion, appCodeName.

value  The value of an object depends on the type of object it is applied to.

ObjectValue Attribute
button, reset, submitValue attribute that appears on-screen, not the button name
checkboxOn if item is selected, off if not
radioString reflection of value
hidden, text, textareaContents of the field
selectReflection of option value
passwordReturns a valid default value, but an encrypted version if modified by the user

Changing the value of a text or textarea object results in an immediate update to the screen. All other form objects are not graphically updated when changed.

Property of button, checkbox, hidden, options, password, radio, reset, submit, text, textarea. For password, text, and textarea, see defaultValue property; for button, reset, and submit, see name property; for options, see properties defaultSelected, selected, selectedIndex, text; for checkbox and radio, see properties checked and defaultChecked.

vlinkColor  Returns or sets the color of visited links using hexadecimal RGB triplets or a string literal. The property cannot be set after the document has been formatted. To override the browser defaults, color settings are used with the onLoad event handler in the <BODY> tag:

<BODY onLoad="document.vlinkColor='aliceblue'">

Property of document. See properties alinkColor, bgColor, fgColor, linkColor.

window  A synonym for the current window to remove ambiguity between a window and form object of the same name. While it also applies to the current frame, it is less ambiguous to use the self property.

Property of frame and window. See self property.

Methods

Methods are functions and procedures used to perform an operation on an object, variable, or constant. With the exception of built-in functions, methods must be used with an object:

object.method()

Even if the method does not require any arguments, the parentheses are still required.

The object which utilizes the method is listed after the definition and is followed by any cross-references to other methods. Stand-alone functions that are not used with objects are indicated with an asterisk (*).

abs  Returns the absolute (unsigned) value of its argument.

document.write(Math.abs(-10));
document.write(Math.abs(12))

The above examples return 10 and 12, respectively.

Method of Math.

acos  Returns the arc cosine (from zero to pi radians) of its argument. The argument should be a number between -1 and 1. If the value is outside the valid range, a zero is returned.

Method of Math. See methods asin, atan, cos, sin, tan.

alert  Displays a JavaScript Alert dialog box with an OK button and a user-defined message. Before the user can continue, he must press the OK button.

Method of window. See methods confirm and prompt.

anchor  Used with write or writeln methods, anchor creates and displays an HTML hypertext target. The syntax is:

textString.anchor(anchorName)

where textString is what the user sees, and anchorName is equivalent to the name attribute of an HTML <ANCHOR> tag.

Method of string. See link method.

asin  Returns the arc sine (between -pi/2 and pi/2 radians) of a number between -1 and 1. If the number is outside the range, a zero is returned.

Method of Math. See methods acos, atan, cos, sin, tan.

atan  Returns the arc tangent (between -pi/2 and pi/2 radians) of a number between -1 and 1. If the number is outside the range, a zero is returned.

Method of Math. See methods acos, asin, cos, sin, tan.

back  Recalls the previous URL from the history list. This method is the same as history.go(-1).

Method of history. See methods forward and go.

big  Formats a string object as a big font by encasing it with HTML <BIG> tags. Both of the following examples result in the same output-displaying the message "Welcome to my home page" in a big font:

var welcomeMessage = "Welcome to my home page."
document.write(welcomeMessage.big())
<BIG> Welcome to my home page.</BIG>

Method of string. See methods fontsize, small.

blink  Formats a string object as a blinking line by encasing it with HTML <BLINK> tags. Both of the following examples produce a flashing line that says "Notice":

var attentionMessage = "Notice"
document.write(attentionMessage.blink())
<BLINK>Notice</BLINK>

Method of string. See methods bold, italics, strike.

blur  Removes focus from the specified form element. For example, the following line removes focus from feedback:

feedback.blur()

assuming that feedback is defined as:

<input type="text" name="feedback">

Method of password, select, text, textarea. See methods focus and select.

bold  Formats a string object in bold text by encasing it with HTML <B> tags.

Method of string. See methods blink, italics, strike.

ceil  Returns the smallest integer greater than, or equal to, its argument. For example,

Math.ceil(1.01)

returns a 2.

Method of Math. See floor method.

charAt  Returns the character from a string at the specified index. The first character is at position zero and the last at length -1.

var userName = "Bobba Louie"
document.write(userName.charAt(4)

returns an "a."

Method of string. See methods indexOf and lastIndexOf.

clear  Clears the contents of a window, regardless of how the window is filled.

Method of document. See methods close, open, write, writeln.

clearTimeout  Cancels a timeout set with the setTimeout method. A timeout is set using a unique timeout ID, which must be used to clear it:

clearTimeout(waitTime)

Method of frame and window. See setTimeout method.

click  Simulates a mouse click on the calling form element with the effect dependent on the type of element.

Form ElementAction
Button, reset, and submitSame as clicking button
RadioSelects radio button
CheckboxMarks checkbox and sets value to on

Method of button, checkbox, radio, reset, submit.

close  For a document object, closes the current stream of output and forces its display. It also stops the browser Winsock animation and displays "Document: Done" in the status bar.

For a window object, closes the current window. As with all window commands, the window object is assumed. For example,

window.close()
close()
self.close()

all close the current window.

Method of document and window. See methods clear, open, write, writeln.

confirm  Displays a JavaScript confirmation dialog box with a message and buttons for OK and Cancel. Confirm returns a true if the user selects OK and false for Cancel. The following example loads a new window if the user presses OK:

if (confirm("Are you sure you want to enter.") {
tourWindow = window.open("http:\\www.haunted.com\","hauntedhouse")
}

Method of window. See methods alert and prompt.

cos  Returns the cosine of the argument. The angle's size must be expressed in radians.

Method of Math. See methods acos, asin, atan, sin, tan.

escape*  Returns ASCII code of its argument based on the ISO Latin-1 character set in the form %xx, where xx is the ASCII code. It is not associated with any other object, but is actually part of the JavaScript language.

See unescape method.

eval*  This built-in function takes a string or numeric expression as its argument. If a string, it attempts to convert it to a numeric expression. Eval then evaluates the expression and returns the value.

var x = 10
var y = 20
document.write(eval("x + y"))

This method can also be used to perform JavaScript commands included as part of a string.

var doThis = "if (x==10) { alert("Your maximum has been reached") }
function checkMax () {
x++;
eval(doThis)
}

This can be useful when converting a date from a form (always a string) into a numerical expression or number.

exp  Returns e (Euler's constant) to the power of the argument to compute a natural logarithm.

Method of Math. See methods log and pow.

fixed  Formats the calling string into a fixed-pitch font by encasing it in HTML <TT> tags.

Method of string.

floor  Returns the integer less than, or equal to, its argument. For example,

Math.floor(2.99)

returns a 2.

Method of Math. See ceil method.

focus  Navigates to a specific form element and gives it focus. From that point, a value can be entered by JavaScript commands or the user can complete the entry.

Method of password, select, text, textarea. See methods blur and select.

fontcolor  Formats the string object to a specific color expressed as a hexadecimal RGB triplet or a string literal, similar to using <FONT COLOR=COLOR>.

Method of string.

fontsize  Formats the string object to a specific font size: one of the seven defined sizes using an integer through the <FONTSIZE=SIZE> tag. If a string is passed, then the size is changed relative to the value set in the <BASEFONT> tag.

Method of string. See methods big and small.

forward  Loads the next document on the URL history list. This method is the same as history.go(1).

Method of history. See methods back and go.

getDate  Returns the day of the month as an integer between 1 and 31.

Method of Date. See setDate method.

getDay  Returns the day of the week as an integer from zero (Sunday) to six (Saturday). There is not a corresponding setDay command because the day is automatically computed when the date value is assigned.

Method of Date.

getHours  Returns the hour of the day in 24-hour format, from zero (midnight) to 23 (11 PM).

Method of Date. See setHours method.

getMinutes  Returns the minutes with an integer from zero to 59.

Method of Date. See setMinutes method.

getMonth  Returns the month of the year as an integer between zero (January) and 11 (December).

Method of Date. See setMonth method.

getSeconds  Returns the seconds in an integer from zero to 59.

Method of Date. See setSeconds method.

getTime  Returns an integer representing the current value of the date object. The value is the number of milliseconds since midnight, January 1, 1970. This value can be used to compare the length of time between two date values.

For functions involving computation of dates, it is useful to define variables defining the minutes, hours, and days in milliseconds:

var dayMillisec = 1000 * 60 * 60 * 24 //1,000 milliseconds x 60 sec x 60  24 hrs

var hourMillisec = 1000 * 60 * 60 //1,000 milliseconds x 60 sec x 60 min

var minuteMillisec = 1000 * 60 //1,000 milliseconds x 60 sec

Method of Date. See setTime method.

getTimezoneOffset  Returns the difference in minutes between the client machine and Greenwich Mean Time. This value is a constant except for daylight savings time.

Method of Date.

getYear  Returns the year of the date object minus 1900. For example, 1996 is returned as 96.

Method of Date. See setYear method.

go  Loads a document specified in the history list by its URL or relative to the current position on the list. If the URL is incomplete, then the closest match is used. The search is not case-sensitive.

Method of history. See methods back and forward.

indexOf  Returns the location of a specific character or string, starting the search from a specific location. The first character of the string is specified as zero and the last is the string's length-1. The syntax is:

stringName.indexOf([character|string], [startingPoint])

The startingPoint is zero by default.

Method of string. See methods charAt and lastIndexof.

isNaN*  For UNIX platforms only, this stand-alone function returns true if the argument is not a number. On all platforms except Windows, the parseFloat and parseInt return NaN when the argument is not a number.

See methodS parseFloat and parseInt.

italics  Formats a string object into italics by encasing it an HTML <I> tag.

Method of string. See methods blink, bold, strike.

lastIndexOf  Returns the index of a character or string in a string object by looking backwards from the end of the string or a user-specified index.

Method of string. See methods charAt and indexOf.

link  Creates a hypertext link to another URL by defining the <HREF> attribute and the text representing the link to the user.

Method of string. See anchor method.

log  Returns the natural logarithm (base e) of a positive numeric expression greater than zero. An out-of-range number always returns -1.797693134862316e+308.

Method of Math. See methods exp and pow.

max  Returns the greater of its two arguments. For example,

Math.max(1,100)

returns 100.

Method of Math. See min method.

min  Returns the lesser of its two arguments.

Method of Math. See max method.

open  For a document, opens a stream to collect the output of write or writeln methods. If a document already exists in the target window, then the open method clears it. The stream is ended by using the document.close() method.

For a window, it opens a new browser window in a similar fashion to choosing File, New Web Browser from the Netscape menu. Using the URL argument, it loads a document into the new window; otherwise, the new window is blank. When used as part of an event handler, the form must include the window object; otherwise, the document is assumed. Window features are defined by a comma-separated list of options with =1 or =yes to enable and =0 or =no to disable. Window features include toolbar, location, directories, status, menubar, scrollbars, resizable, copyhistory, width, and height.

Method of document and window. See methods clear, close, write, writeln.

parse  Takes a date string, such as "Jan 11, 1996", and returns the number of milliseconds since midnight, Jan. 1, 1970. This function can be used to set date values based on string values. When passed a string with a time, it returns the time value.

Because parse is a static function of Date, it is always used as Date.parse() rather than as a method of a created date object.

Method of Date. See UTC method.

parseFloat*  Parses a string argument and returns a floating-point number if the first character is a plus sign, minus sign, decimal point, exponent, or a numeral. If it encounters a character other than one of the valid choices after that point, it returns the value up to that location and ignores all succeeding characters. If the first character is not a valid character, parseFloat returns one of two values based on the platform:

Windows  0
Non-WindowsNaN

See isNaN method.

parseInt*  Parses a string argument and returns an integer based on a specified radix or base. A radix of 10 converts the value to a decimal, while eight converts to octal, and 16 to hexadecimal. Values greater than 10 for bases above 10 are represented with letters (A through F) in place of numbers.

Floating-point values are converted to integers. The rules for evaluating the string are identical to parseFloat.

See isNaN and parseFloat methods.

pow  Returns a base raised to an exponent.

Method of Math. See exp and log methods.

prompt  Displays a prompt dialog box that accepts user input. If an initial value is not specified for inputDefault, the dialog box displays the value <undefined>.

Method of window. See alert and confirm methods.

random  On UNIX machines only, returns a pseudo-random number between zero and 1.

Method of Math.

round  Returns the value of a floating-point argument rounded to the next highest integer if the decimal portion is greater than or equal to .5, or the next lowest integer if less than .5.

Method of Math.

select  Selects the input area of a specified form element. Used in conjunction with the focus method, JavaScript can highlight a field and position the cursor for user input.

Method of password, text, textarea. See methods blur and focus.

setDate  Sets the day of the month.

Method of Date. See getDate method.

setHours  Sets the hour for the current time.

Method of Date. See getHours method.

setMinutes  Sets the minutes for the current time.

Method of Date. See getMinutes method.

setMonth  Sets the month with an integer from zero (January) to 11 (December).

Method of Date. See getMonth method.

setSeconds  Sets the seconds for the current time.

Method of Date. See getSeconds method.

setTime  Sets the value of a date object.

Method of Date. See getTime method.

setTimeout  Evaluates an expression after a specified amount of time, expressed in milliseconds. This is not repeated indefinitely. For example, setting a timeout to three seconds will evaluate the expression once after three seconds-not every three seconds. To call setTimeout recursively, reset the timeout as part of the function invoked by the method. Calling the function startclock in the following example sets a loop in motion that clears the timeout, displays the current time, and sets the timeout to redisplay the time in one second.

var timerID = null;
var timerRunning = false;
function stopclock () {
if(timerRunning) cleartimeout(timerID);
timerRunning=false;
}
function startclock () {
stopclock();
showtime();
}
function showtime () {
var now = new Date();
...
document.clock.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}

Method of window. See clearTimeout method.

setYear  Sets the year in the current date using an integer representing the year minus 1900.

Method of Date. See getYear method.

sin  Returns the sine of an argument. The argument is the size of an angle expressed in radians, and the returned value is from -1 to 1.

Method of Math. See methods acos, asin, atan, cos, tan.

small  Formats a string object into a small font using the HTML <SMALL> tags.

Method of string. See methods big and fontsize.

sqrt  Returns the square root of a positive numeric expression. If the argument's value is outside the range, the returned value is zero.

strike  Formats a string object as strikeout text using the HTML <STRIKE> tags.

Method of string. See methods blink, bold, italics.

sub  Formats a string object into subscript text using the HTML <SUB> tags.

Method of string. See sup method.

submit  Performs the same action as clicking a submit button.

Method of form. See submit object; see onSubmit event handler.

substring  Returns a subset of a string object based on two indexes. If the indexes are equal, an empty string is returned. Regardless of order, the substring is built from the smallest index to the largest.

Method of string.

sup  Formats a string object into superscript text using the HTML <SUP> tags.

Method of string. See sub method.

tan  Returns the tangent of an argument. The argument is the size of an angle expressed in radians.

Method of Math. See methods acos, asin, atan, cos, sin.

toGMTString  Converts a date object to a string using Internet Greenwich Mean Time (GMT) conventions. For example, if today is a date object:

today.toGMTString()

then the string "Mon, 18 Dec 1995 17:28:35 GMT" is returned. Actual formatting may vary from platform to platform. The time and date is based on the client machine.

Method of Date. See toLocaleString method.

toLocaleString  Converts a date object to a string using the local conventions, such as mm/dd/yy hh:mm:ss.

Method of Date. See toGMTString method.

toLowerCase  Converts all characters in a string to lowercase.

Method of string. See toUpperCase method.

toString  Converts a date or location object to a string.

Method of Date, location.

toUpperCase  Converts all characters in a string to uppercase.

Method of string. See toLowerCase method.

unEscape*  Returns a character based on its ASCII value expressed as a string in the format %xxx where xxx is a decimal number between zero and 255, or 0 ¥ 0 to 0 ¥ FF in hex.

See escape method.

UTC  Returns the number of milliseconds for a date in Universal Coordinated Time (UTC) since midnight, January 1, 1970.

UTC is a constant, and is always used as Date.UTC(), not with a created date object.

Method of Date. See parse method.

write  Writes one or more lines to a document window, and can include HTML tags and JavaScript expressions, including numeric, string, and logical values. The write method does not add a new line (<BR> or /N) character to the end of the output. If called from an event handler, the current document is cleared if a new window is not created for the output.

Method of document. See methods close, clear, open, writeln.

writeln  Writes one or more lines to a document window followed by a new line character, and can include HTML tags and JavaScript expressions, including numeric, string, and logical values. If called from an event handler, the current document is cleared if a new window is not created for the output.

Method of document. See methods close, clear, open, write.

Event Handlers

Event handlers are where JavaScript gets its power. By looking for specific user actions, JavaScript can confirm or act on input immediately, without waiting for server introduction.

onBlur  Blurs occur when a select, text, or textarea field on a form loses focus.

Event handler of select, text, textarea. See event handlers onChange and onFocus.

onChange  A change event happens when a select, text, or textarea element on a form is modified before losing focus.

Event handler of select, text, textarea. See event handlers onBlur, onFocus.

onClick  Occurs when an object, such as a button or checkbox, is clicked.

Event handler of button, checkbox, radio, link, reset, submit.

onFocus  A form element receives focus by tabbing to or clicking the input area with the mouse. Selecting within a field results in a select event.

Event handler of select, text, textarea. See event handlers onBlur and onChange.

onLoad  A load event is created when Navigator finishes loading a window or all frames within a <FRAMESET> tag.

Event handler of window. See onUnload event handler.

onMouseOver  Occurs when the mouse pointer is placed over a link object. To function with the status or defaultStatus properties, the event handler must return true.

Event handler of link.

onSelect  A select event is triggered by selecting some or all of the text in a text or textarea field.

Event handler of text, textarea.

onSubmit  Triggered by the user submitting a form. The event handler must return true to allow the form to be submitted to the server. Conversely, it returns false to block the form's submission.

Event handler of form. See submit object and method.

onUnload  Occurs when exiting a document. For proper operation, place the onUnload handler in the <BODY> or <FRAMESET> tags.

Event handler of window. See onLoad event handler.