Notice: This material is excerpted from Special Edition Using JavaScript, ISBN: 0-7897-0789-6. The electronic version of this material has not been through the final proof reading stage that the book goes through before being published in printed form. Some errors may exist here that are corrected before the book is published. This material is provided "as is" without any warranty of any kind.
While not necessarily JavaScript objects or keywords, the following items 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.
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. On-line 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 which 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.
Attributes of HTML tags embedded in documents. The attribute assigns a JavaScript command or function to execute when the event happens.
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.
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.
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.
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.
An absolute value not assigned to a variable. Examples include 1, 3.1415927, "Bob", true.
A function assigned to an object. For example, bigString.toUpperCase() returns an uppercase version of the string contained in bigString.
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.
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 D, "JavaScript Commands and Grammar," for a list of operators and their precedence.
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.
One or more JavaScript commands enclosed with a <script> tag.
JavaScript is an object-oriented language, so at its heart are a pre-defined 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.
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.
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.
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.
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.
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 onLoad and onUnload event handlers.
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. It's value is accessed in three ways:
formName.elements[1].value formName.elements["newPassword"].value formName.newPassword.value
Values can not be set or changed using the read-only elements array.
Property of form. See length PROPERTY.
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.
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 document and window OBJECTS; see PROPERTIES defaultStatus, frames, parent, self, status, top, window; see METHODS setTimeout and clearTimeout.
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.
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.
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 onClick and onMouseOver EVENT HANDLERS.
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.
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.
Contains information on the current version of Navigator used by the client.
See OBJECTS link and anchors; see PROPERTIES appName, appCodeName, appVersion, userAgent.
Created by HTML password text fields, and are 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.
Objects created within HTML <form> tags and represent 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.
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.
A selection list or scrolling list on an HTML form. A selection list enables the user 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.
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 text and textarea OBJECTS; see length PROPERTY; see METHODS anchor, big, blink, bold, charAt, fixed, fontcolor, fontsize, indexOf, italics, lastIndexOf, link, small, strike, sub, substring, sup, toLowerCase, toUpperCase.
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 METHOD click; see EVENT HANDLER onClick.
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.
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.
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 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 which make it specific.
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.
The color of a link after the mouse button is depressed-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.
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.
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, this returns:
The code name of your browser is Mozilla
Property of navigator. See PROPERTIES appName, appVersion, userAgent.
Returns a read-only string with the name of the browser.
Property of navigator. See PROPERTIES appCodeName, appVersion, userAgent.
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.
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.
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.
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 under TERMS.
Property of document. See hidden OBJECT.
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.
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.
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.
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.
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.
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.
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.
The color of foreground text represented as a hexadecimal RGB triplet or a sting 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 METHODS.
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.
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.
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 a 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.
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.
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.
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.
Returns the index of an option in a select element with zero being the first item.
Property of options. See PROPERTIES defaultSelected, selected, selectedIndex.
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.
An integer reflecting a length- or size-related property of an object.
Object Property Measured
Property of anchors, elements, forms, frame, frames, history, links, options, radio, , string, window.
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.
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.
A constant representing the natural logarithm of 2 (approximately 0.693).
Property of Math. See PROPERTIES E, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2.
A constant representing the natural logarithm of 10 (approximately 2.302).
Property of Math. See PROPERTIES E, LN2, LOG2E, LOG10E, PI, SQRT1_2, SQRT2.
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.
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.
A constant representing the base 10 logarithm of e (approximately .434).
Property of Math. See PROPERTIES E, LN2, LN10, LOG2E, SQRT1_2, SQRT2.
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.
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.
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.
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.
Returns the path portion from an 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
The square root of 2 (approximately 1.414).
Property of Math. See properties E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2.
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.
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.
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 limitations while the value is changed, its appearance on-screen is not.
Property of options.
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.
The top-most window, called an ancestor or Web browser window, that contains frames or nested framesets.
Property of window.
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.
The value of an object depends on the type of object it is applied to.
Object Value Attribute
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.
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.
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 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 parantheses are still required.
The object which utilizes the method is listed after the definition as "Method of object," followed by any cross-references to other methods. Stand-alone functions that are not used with objects are indicated with an asterisk (*).
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.
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.
Displays a JavaScript Alert dialog box with an OK button and a user-defined message. Before the user can continue, they must press the OK button.
Method of window. See METHODS confirm and prompt.
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.
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.
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.
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.
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.
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.
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.
Formats a string object in bold text by encasing it with HTML <b> tags.
Method of string. See METHODS blink, italics, strike.
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.
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.
Clears the contents of a window, regardless of how the window was filled.
Method of document. See METHODS close, open, write, writeln.
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.
Simulates a mouse click on the calling form element with the effect dependent on the type of element.
Form Element Action
Method of button, checkbox, radio, reset, submit.
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.
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 closes loads a new window if the user presses o.k.:
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.
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.
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.
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.
Returns e (Euler's constant) to the power of the argument to compute a natural logarithm.
Method of Math. See METHODS log and pow.
Formats the calling string into a fixed-pitch font by encasing it in HTML <tt> tags.
Method of string.
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.
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.
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.
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.
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.
Returns the day of the month as an integer between 1 and 31.
Method of Date.
See setDate method.
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.
Returns the hour of the day in 24-hour format, from zero (midnight) to 23 (11 PM).
Method of Date. See setHours METHOD.
Returns the minutes with an integer from zero to 59.
Method of Date. See setMinutes METHOD.
Returns the month of the year as an integer between zero (January) and 11 (December).
Method of Date. See setMonth METHOD.
Returns the seconds in an integer from zero to 59.
Method of Date. See setSeconds METHOD.
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 min x 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.
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.
Returns the year of the date object minus 1900. For example, 1996 is returned as 96.
Method of Date. See setYear METHOD.
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.
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.
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.
Formats a string object into italics by encasing it an HTML <I> tag.
Method of string. See METHODS blink, bold, strike.
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.
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.
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.
Returns the greater of its two arguments. For example:
Math.max(1,100)
returns 100.
Method of Math. See min METHOD.
Returns the lesser of its two arguments.
Method of Math. See max METHOD.
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.
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.
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:
See isNaN METHOD.
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.
Returns a base raised to an exponent.
Method of Math. See exp and log METHODS.
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.
On UNIX machines only, returns a pseudo-random number between zero and 1.
Method of Math.
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.
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.
Sets the day of the month.
Method of Date. See getDate METHOD.
Sets the hour for the current time.
Method of Date. See getHours METHOD.
Sets the minutes for the current time.
Method of Date. See getMinutes METHOD.
Sets the month with an integer from zero (January) to 11 (December).
Method of Date. See getMonth METHOD.
Sets the seconds for the current time.
Method of Date. See getSeconds METHOD.
Sets the value of a date object.
Method of Date. See getTime METHOD.
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.
Sets the year in the current date using an integer representing the year minus 1900.
Method of Date. See getYear METHOD.
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.
Formats a string object into a small font using the HTML <small> tags.
Method of string. See METHODS big and fontsize.
Returns the square root of a positive numeric expression. If the argument's value is outside the range, the returned value is zero.
Formats a string object as strikeout text using the HTML <strike> tags.
Method of string. See METHODS blink, bold, italics.
Formats a string object into subscript text using the HTML <sub> tags.
Method of string. See sup METHOD.
Performs the same action as clicking a submit button.
Method of form. See submit OBJECT; see onSubmit EVENT HANDLER.
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.
Formats a string object into superscript text using the HTML <sup> tags.
Method of string. See sub METHOD.
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.
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.
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.
Converts all characters in a string to lowercase.
Method of string. See toUpperCase METHOD.
Converts a date or location object to a string.
Method of Date, location.
Converts all characters in a string to uppercase.
Method of string.
See toLowerCase method.
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 0x0 to 0xFF in hex.
See escape METHOD.
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.
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.
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 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. Since user activity within an HTML page is limited to mouse movement and input on form elements.
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.
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.
Occurs when an object, such as a button or checkbox, is clicked.
Event handler of button, checkbox, radio, link, reset, submit.
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.
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.
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.
A select event is triggered by selecting some or all of the text in a text or textarea field.
Event handler of text, textarea.
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.
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.
|