appendix B

JavaScript Language Reference


CONTENTS


The first part of this reference is organized by object with properties and methods listed by the object they apply to. The second part covers independent functions in JavaScript not connected with a particular object, as well as operators in JavaScript.

The following codes are used to indicate where objects, methods, properties and event handlers are implemented:

The anchor Object [C|2|3|I]

The anchor object reflects an HTML anchor.

Property

The applet Object [C|3]

The applet object reflects a Java applet included in a Web page with the APPLET tag.

Property

The area Object [C|3]

The area object reflects an clickable area defined in an imagemap. area objects appear as entries in the links array of the document object.

Properties

Event Handlers

The Array Object [C|3|I]

Provides a mechanism for creating arrays and working with them. New arrays are created with arrayName = new Array() or arrayName = new Array(arrayLength).

Properties

Methods

The button Object [C|2|3|I]

The button object reflects a push button from an HTML form in JavaScript.

Properties

Methods

Event Handlers

The checkbox Object [c|2|3|I]

The checkbox object makes a checkbox in an HTML form available in JavaScript.

Properties

Methods

Event Handlers

The combo Object [C|I]

The combo object reflects a combo field into JavaScript.

Properties

Methods

Event Handlers

The Date Object [C|2|3|I]

The Date object provides mechanisms for working with dates and times in JavaScript. Instances of the object can be created with the syntax

newObjectName = new Date(dateInfo)

Where dateInfo is an optional specification of a particular date and can be one of the following:

"month day, year hours:minutes:seconds"

year, month, day

year, month, day, hours, minutes, seconds

where the latter two options represent integer values.

If no dateInfo is specified, the new object will represent the current date and time.

Property

Methods

Day, DD Mon YYYY HH:MM:SS TZN

Mon DD, YYYY

The document Object [C|2|3|I]

The document object reflects attributes of an HTML document in JavaScript.

Properties

Methods

The FileUpload Object [C|3]

Reflects a file upload element in an HTML form.

Properties

The form Object [C|2|3|I]

The form object reflects an HTML form in JavaScript. Each HTML form in a document is reflected by a distinct instance of the form object.

Properties

Methods

Event Handlers

The frame Object [C|2|3|I]

The frame object reflects a frame window in JavaScript.

Properties

Methods

toolbar=[yes,no,1,0] Indicates if the window should have a toolbar
location=[yes,no,1,0] Indicates if the window should have a location field
directories=[yes,no,1,0] Indicates if the window should have directory buttons
status=[yes,no,1,0] Indicates if the window should have a status bar
menubar=[yes,no,1,0] Indicates if the window should have menus
scrollbars=[yes,no,1,0] Indicates if the window should have scroll bars
resizable=[yes,no,1,0] Indicates if the window should be resizable
width=pixels Indicates the width of the window in pixels
height=pixels Indicates the height of the window in pixels

Event Handlers

The Function Object [C|3]

The Function object provides a mechanism for indicating JavaScript code to compile as a function. The syntax to use the Function object is functionName = new Function(arg1, arg2, arg3, ..., functionCode). This is similar to

function functionName(arg1, arg2, arg3, ...) {
   functionCode
}

except that in the former, functionName is a variable with a reference to the function, and the function is evaluated each time it is used rather than being compiled once.

Properties

The hidden Object [C|2|3|I]

The hidden object reflects a hidden field from an HTML form in JavaScript.

Properties

The history Object [C|2|3|I]

The history object allows a script to work with the Navigator browser's history list in JavaScript. For security and privacy reasons, the actual content of the list is not reflected into JavaScript.

Property

Methods

The Image Object [C|3]

The Image object reflects an image included in an HTML document.

Properties

Event Handlers

The link Object [C|2|3|I]

The link object reflects a hypertext link in the body of a document.

Properties

Event Handlers

The location Object [C|2|3|I]

The location object reflects information about the current URL.

Properties

Methods

The Math Object [C|2|3|I]

The Math object provides properties and methods for advanced mathematical calculations.

Properties

Methods

The mimeType Object [C|3]

The mimeType object reflects a MIME type supported by the client browser.

Properties

The navigator Object [C|2|3|I]

The navigator object reflects information about the version of Navigator being used.

Properties

Method

The Option Object [C|3]

The Option object is used to create entries in a select list using the syntax optionName = new Option(optionText, optionValue, defaultSelected, selected) and then selectName.options[index] = optionName.

Properties

The password Object [C|2|3|I]

The password object reflects a password text field from an HTML form in JavaScript.

Properties

Methods

Event Handlers

The plugin Object

The plugin object reflects a plug-in supported by the browser.

Properties

The radio Object [C|2|3|I]

The radio object reflects a set of radio buttons from an HTML form in JavaScript. To access individual radio buttons, use numeric indexes starting at zero. For instance, individual buttons in a set of radio buttons named testRadio could be referenced by testRadio[0], testRadio[1], etc.

Properties

Methods

Event Handlers

The reset Object [C|2|3|I]

The reset object reflects a reset button from an HTML form in JavaScript.

Properties

Methods

Event Handlers

The select Object [C|2|3]

The select object reflects a selection list from an HTML form in JavaScript.

Properties

defaultSelected A boolean value indicating if an option was selected by default (i.e., reflects the SELECTED attribute).
index An integer value reflecting the index of an option.
length An integer value reflecting the number of options in the selection list.
name A string value containing the name of the selection list
selected A boolean value indicating if the option is selected. Can be used to select or deselect an option.
selectedIndex An integer value containing the index of the currently selected option.
text A string value containing the text displayed in the selection list for a particular option.
value A string value indicating the value for the specified option (i.e., reflects the VALUE attribute).

Methods

Event Handlers

The String Object [C|2|3|I]

The String object provides properties and methods for working with string literals and variables.

Properties

Methods

The submit Object [C|2|3|I]

The submit object reflects a submit button from an HTML form in JavaScript.

Properties

Methods

Event Handlers

The text Object [C|2|3|I]

The text object reflects a text field from an HTML form in JavaScript.

Properties

Methods

Event Handlers

The textarea Object [C|2|3|I]

The textarea object reflects a multiline text field from an HTML form in JavaScript.

Properties

Methods

Event Handlers

The window Object [C|2|3|I]

The window object is the top-level object for each window or frame and is the parent object for the document, location, and history objects.

Properties

Methods

toolbar=[yes,no,1,0] Indicates if the window should have a toolbar
location=[yes,no,1,0] Indicates if the window should have a location field
directories=[yes,no,1,0] Indicates if the window should have directory buttons
status=[yes,no,1,0] Indicates if the window should have a status bar
menubar=[yes,no,1,0] Indicates if the window should have menus
scrollbars=[yes,no,1,0] Indicates if the window should have scroll bars
resizable=[yes,no,1,0] Indicates if the window should be resizable
width=pixels Indicates the width of the window in pixels
height=pixels Indicates the height of the window in pixels

Event Handlers

Independent Functions, Operators, Variables, and Literals

Independent Functions

Operators

Table B.1. Assignment operators.

OperatorDescription
=Assigns value of right operand to the left operand
+= Adds the left and right operands and assigns the result to the left operand
-= Subtracts the right operand from the left operand and assigns the result to the left operand
*= Multiplies the two operands and assigns the result to the left operand
/= Divides the left operand by the right operand and assigns the value to the left operand
%= Divides the left operand by the right operand and assigns the remainder to the left operand

Table B.2. Arithmetic operators.

OperatorDescription
+Adds the left and right operands
-Subtracts the right operand from the left operand
*Multiplies the two operands
/Divides the left operand by the right operand
%Divides the left operand by the right operand and evaluates to the remainder
++ Increments the operand by one (can be used before or after the operand)
-- Decreases the operand by one (can be used before or after the operand)
-Changes the sign of the operand

Table B.3. Bitwise operators in JavaScript.

OperatorDescription
AND (or &) Converts operands to integers with 32 bits, pairs the corresponding bits and returns one for each pair of ones. Returns zero for any other combination.
OR (or |) Converts operands to integers with 32 bits, pairs the corresponding bits and returns one for each pair where one of the two bits is one. Returns zero if both bits are zero.
XOR (or ^) Converts operands to integer with 32 bits, pairs the corresponding bits and returns one for each pair where only one bit is one. Returns zero for any other combination.
<< Converts the left operand to an integer with 32 bits and shifts bits to the left the number of bits indicated by the right operand-bits shifted off to the left are discarded and zeros are shifted in from the right.
>> Converts the left operand to an integer with 32 bits and shifts bits to the right the number of bits indicated by the right operand-bits shifted off to the right are discarded and copies of the leftmost bit are shifted in from the left.

Table B.4. Logical operators.

OperatorDescription
&& Logical "and"-returns true when both operands are true, otherwise it returns false.
|| Logical "or"-returns true if either operand is true. It only returns false when both operands are false.
!Logical "not"-returns true if the operand is false and false if the operand is true. This is a unary operator and precedes the operand.

Table B.5. Logical (comparison) operators.

OperatorDescription
== Returns true if the operands are equal
!= Returns true if the operands are not equal
> Returns true if the left operand is greater than the right operand
< Returns true if the left operand is less than the right operand
>= Returns true if the left operand is greater than or equal to the right operand
<= Returns true if the left operand is less than or equal to the right operand

comma (,)
assignment operators (= += -= *= /= %=)
conditional (? :)
logical or (||)
logical and (&&)
bitwise or (|)
bitwise xor (^)
bitwise and (&)
equality (== !=)
relational (< <= > >=)
shift (<< >> >>>)
addition/subtraction (+ -)
multiply/divide/modulus (* / %)
negation/increment (! - ++ --)
call, member (() [])