While not necessarily JScript objects or keywords, the following items can help in your understanding of JScript and how it works. These are the general terms that are used in most discussions about JScript 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. 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 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 JScript 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.
Browser 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 browser 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 compiler, such as the Java Development Kit, and the Java 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. JScript is Microsoft's implementation of JavaScript for their Internet Explorer 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 JScript 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 C, "JScript 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 JScript that contain constants: values that never change.
One or more JScript commands enclosed with a <script> tag.
JScript is an object-oriented language, so at its heart are a predefined set of objects that 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 that is set in HTML with <A> tags. To determine how many anchors are included in a document, use the length property.
document.anchors.length
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 whether 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 representations 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 the browser 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, check boxes, radio buttons, text, and text area 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.
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 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 the browser 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 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.
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 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.
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 used only 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 their 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 the browser 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, opener, 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.
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 Internet Explorer, this returns:
The code name of your browser is Microsoft Internet Explorer 3.0A
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 Internet Explorer 3.0:
document.write(navigator.appVersion)
returns
3.0 (Win95; U)
This specifies IE 3.0 running on Windows 95. The U country code specifies a U.S. release, while an I would indicate 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 check box 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 the browser in a client-side cookies folder or 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 check box 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 browser 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 Internet Explorer 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 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 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 an 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.
Returns a string formed by combining the hostname and port properties of an 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 an 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 JScript (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 |
history | Length of the history list |
string | Integer length of the string; zero for a null string |
radio | Number 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.
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 object's 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 (set using the HTML NAME attribute) 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), JScript 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.
Returns the window object from which the current window was opened. For example, if window A issues a window.open() call to create window B, then the value of document.opener in window B is "A."
Note: This property is supported only under Internet Explorer at this time. Do not use this property if you want to maintain compatibility with Netscape's JavaScript.
Property of window. See also parent and top.
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 an 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, and so on).
Property of link and location.
See PROPERTIES hash, host, hostname, href, pathname, port, search.
document.write("You came here from a page at " + document.referrer)
Property of document.
Returns a string containing any query information appended to an 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 names.
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.status='Your message.'; return true">link</A>
Note the use of nested quotes and the required return true statement at the end of the event handler.
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/"
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 limitation-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 topmost 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. Internet Explorer currently returns the string "Mozilla/2.0 (compatible; MSIE 3.0A; Windows 95)" on a Windows 95 platform.
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 |
button, reset, submit | Value attribute that appears on screen, not the button name |
checkbox | On if item is selected, off if not |
radio | String form of value |
hidden, text, textarea | Contents of the field |
select | Reflection of option value |
password | Return 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.
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, used 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 parentheses are still required.
The object that 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 JScript alert dialog box with an OK button and a user-defined message. Before the user can continue, he or she 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 |
Button, Reset, and Submit | Same as clicking button. |
Radio | Selects radio button. |
Checkbox | Marks checkbox and sets value to on. |
Method of button, checkbox, radio, reset, submit.
For a document object, closes the current output stream and forces its display. It also stops the browser icon animation and displays 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 JScript 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.
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 JScript language.
See unescape METHOD.
var x = 10 var y = 20 document.write(eval("x + y"))
This method can also be used to perform JScript commands included as part of a string, as in this example:
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.
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 JScript 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 no corresponding setDay method 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 P.M.).
Method of Date. See setHours METHOD.
Returns the minutes as 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 as 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 (known as The Epoch). 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 giving 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 relative to the current position on the list. If the value given to go is out of range (before the beginning of the history list, or after its end) the nearest valid value is used.
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 at location
zero and the last is at location length-1.
The syntax is:
stringName.indexOf([character|string], [startingPoint])
The startingPoint is zero by default.
Method of string. See METHODS charAt and lastIndexof.
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 from 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.
Method of string. See anchor METHOD.
Returns the natural logarithm (base e) of a positive numeric expression. An out-of-range number always gives an error.
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 New Window from the File 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.open method 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 containing a date, 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 zero.
Parses a string argument and returns an integer based on a specified radix or base. A radix of 10 interprets the string as a decimal number, while eight implies an octal number, and 16 a hexadecimal number.
Floating-point values are converted to integers. The rules for evaluating the string are identical to parseFloat.
See the parseFloat METHOD.
Returns the base argument raised to the 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 a blank value.
Method of window. See alert and confirm METHODS.
Returns a pseudo-random floating-point 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 it is less than .5.
Method of Math.
Selects the input area of a specified form element. Used in conjunction with the focus method, JScript 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. Years before 1970 are not currently permitted.
Method of Date. See getYear METHOD.
Returns the sine of an argument. The argument is 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> tag.
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> tag.
Method of string. See METHODS blink, bold, italics.
Formats a string object into subscript text using the HTML <sub> tag.
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> tag.
Method of string. See sub METHOD.
Returns the tangent of an argument. The argument is 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 are 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 an object to a string. In addition to working on the built-in Date and location objects, it will also work with user-defined objects.
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 %xx where xx is a hexadecimal number between 0x0 and 0xFF.
See escape METHOD.
Returns the number of milliseconds for a date in Universal Coordinated Time (UTC) since midnight, January 1, 1970.
UTC is a static method, 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 JScript 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; can include HTML tags and JScript 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 JScript gets its power. By looking for specific user actions, JScript can confirm or act on input immediately, without waiting for server intervention.
Blurs occur when a select, text, or textarea field in 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 the browser finishes loading a window or a frame within a <frameset> tag.
Event handler of window. See onUnload EVENT HANDLER.
A Microsoft-specific extension of the onMouseOver event. This form of the event permits the event handler to receive the x and y coordinates of the mouse at the time the event occurred, as well as the current state of the mouse button(s) and the shift key. Currently, this event is implemented only for ActiveX controls.
See onMouseOver 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.