The following properties are available in JavaScript:
A string specifying the URL of the server to which form field input information is sent.
formName.action
formName is either the name of a form or an element in the forms array.
The action property is a reflection of the ACTION attribute of the <FORM> tag.
You can set the action property at any time.
Certain values of the action property may require specific values for other form properties. See RFC 1867 for more information.
The following example sets the action property of the musicForm form to the value of the variable urlName:
document.musicForm.action=urlName
A string specifying the color of an active link (after mouse-button down, but before mouse-button up).
document.alinkColor
The alinkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Color Values. This property is the JavaScript reflection of the ALINK attribute of the <BODY> tag. You cannot set this property after the HTML source has been through layout.
If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072".
The following example sets the color of active links to aqua using a string literal:
document.alinkColor="aqua"
The following example sets the color of active links to aqua using a hexadecimal triplet:
document.alinkColor="00FFFF"
An array of objects corresponding to named anchors (<A NAME="anchorName"> tags) in source order.
1. document.anchors[index] 2. document.anchors.length
index is an integer representing an anchor in a document.
The anchors array contains an entry for each <A> tag containing a NAME attribute in a document. For example, if a document contains three anchors, these anchors are reflected as document.anchors[0], document.anchors[1], and document.anchors[2].
To obtain the number of anchors in a document, use the length property: document.anchors.length.
Even though the anchors array represents named anchors, the value of anchors[index] is always null. But if a document names anchors in a systematic way using natural numbers, you can use the anchors array and its length property to validate an anchor name before using it in operations such as setting location.hash. See the example below.
Elements in the anchors array are read-only. For example, the statement document.anchors[0]="anchor1" has no effect.
The following example opens two windows. The first window contains a series of buttons that set location.hash in the second window to a specific anchor. The second window defines four anchors named "0", "1", "2", and "3". (The anchor names in the document are therefore 0, 1, 2, ... (document.anchors.length-1)). When a button is pressed in the first window, the onClick event handler verifies that the anchor exists before setting window2.location.hash to the specified anchor name.
LINK1.HTML, which defines the first window and its buttons, contains the following code:
LINK2.HTML, which contains the anchors, contains the following code:
A string specifying the code name of the browser.
navigator.appCodeName
appCodeName is a read-only property.
The following example displays the value of the appCodeName property:
document.write("The value of navigator.appCodeName is " + navigator.appCodeName)
This example displays information such as the following:
The value of navigator.appCodeName is Mozilla
A string specifying the name of the browser.
navigator.appName
appName is a read-only property.
The following example displays the value of the appName property:
document.write("The value of navigator.appName is " + navigator.appName)
This example displays information such as the following:
The value of navigator.appName is Netscape
A string specifying version information for the Navigator.
navigator.appVersion
The appVersion property specifies version information in the following format:
releaseNumber (platform; country)
The values contained in this format are the following:
appVersion is a read-only property.
The following example displays version information for the Navigator:
document.write("The value of navigator.appVersion is " + navigator.appVersion)
This example displays information such as the following:
The value of navigator.appVersion is 2.0b5 (Win95, I)
A string specifying the color of the document background.
document.bgColor
The bgColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Color Values. This property is the JavaScript reflection of the BGCOLOR attribute of the <BODY> tag. The default value of this property is set by the user on the Colors tab of the Preferences dialog box, which is displayed by choosing General Preferences from the Options menu.
You can set the bgColor property at any time.
If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072".
The following example sets the color of the document background to aqua using a string literal:
document.bgColor="aqua"
The following example sets the color of the document background to aqua using a hexadecimal triplet:
document.bgColor="00FFFF"
A Boolean value specifying the selection state of a checkbox object or radio button.
1. checkboxName.checked 2. radioName[index].checked
checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array.
radioName is the value of the NAME attribute of a radio object.
index is an integer representing a radio button in a radio object.
If a checkbox or radio button is selected, the value of its checked property is true; otherwise, it is false.
You can set the checked property at any time. The display of the checkbox or radio button updates immediately when you set the checked property.
The following example examines an array of radio buttons called musicType on the musicForm form to determine which button is selected. The VALUE attribute of the selected button is assigned to the checkedButton variable.
function stateChecker() {
var i = ""
var checkedButton = ""
for (i in document.musicForm.musicType) {
if (document.musicForm.musicType[i].checked=="1") {
checkedButton=document.musicForm.musicType[i].value
}
}
}
String value of a cookie, which is a small piece of information stored by the Navigator in the cookies.txt file.
document.cookie
Use string methods such as substring, charAt, indexOf, and lastIndexOf to determine the value stored in the cookie. See the Netscape cookie specification for a complete specification of the cookie syntax.
You can set the cookie property at any time.
The following function uses the cookie property to record a reminder for users of an application. The "expires=" component sets an expiration date for the cookie, so it persists beyond the current browser session.
function RecordReminder(time, expression) {
// record a cookie of the form "@<T>=<E>" to map from <T> in milliseconds
// since the epoch, returned by Date.getTime(), onto an encoded expression,
// <E> (encoded to contain no white space, semicolon, or comma characters)
document.cookie = "@" + time + "=" + expression + ";"
// set the cookie expiration time to one day beyond the reminder time
document.cookie += "expires=" + Date(time + 24*60*60*1000)
}
When the user loads the page that contains this function, another function uses indexOf("@") and indexOf("=") to determine the date and time stored in the cookie.
A Boolean value indicating the default selection state of a checkbox or radio button.
1. checkboxName.defaultChecked 2. radioName[index].defaultChecked
checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array.
radioName is the value of the NAME attribute of a radio object.
index is an integer representing a radio button in a radio object.
If an checkbox or radio button is selected by default, the value of the defaultChecked property is true; otherwise, it is false. defaultChecked initially reflects whether the CHECKED attribute is used within an <INPUT> tag; however, setting defaultChecked overrides the CHECKED attribute.
You can set the defaultChecked property at any time. The display of the checkbox or radio button does not update when you set the defaultChecked property, only when you set the checked property.
The following example resets an array of radio buttons called musicType on the musicForm form to the default selection state.
function radioResetter() {
var i=""
for (i in document.musicForm.musicType) {
if (document.musicForm.musicType[i].defaultChecked==true) {
document.musicForm.musicType[i].checked=true
}
}
}
A Boolean value indicating the default selection state of an option in a select object.
selectName.options[index].defaultSelected
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
index is an integer representing an option in a select object.
If an option in a select object is selected by default, the value of the defaultSelected property is true; otherwise, it is false. defaultSelected initially reflects whether the SELECTED attribute is used within an <OPTION> tag; however, setting defaultSelected overrides the SELECTED attribute.
You can set the defaultSelected property at any time. The display of the select object does not update when you set the defaultSelected property, only when you set the selected or selectedIndex properties.
A select object created without the MULTIPLE attribute can have only one option selected by default. When you set defaultSelected in such an object, any previous default selections, including defaults set with the SELECTED attribute, are cleared. If you set defaultSelected in a select object created with the MULTIPLE attribute, previous default selections are not affected.
options property
In the following example, the restoreDefault() function returns the musicType select object to its default state. The for loop uses the options array to evaluate every option in the select object. The if statement sets the selected property if defaultSelected is true.
function restoreDefault() {
for (var i = 0; i < document.musicForm.musicType.length; i++) {
if (document.musicForm.musicType.options[i].defaultSelected == true) {
document.musicForm.musicType.options[i].selected=true
}
}
}
The previous example assumes that the select object is similar to the following:
<SELECT NAME="musicType"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT>
The default message displayed in the status bar at the bottom of the window.
windowReference.defaultStatus
windowReference is a valid way of referring to a window, as described in the window object.
The defaultStatus message appears when nothing else is in the status bar. Do not confuse the defaultStatus property with the status property. The status property reflects a priority or transient message in the status bar, such as the message that appears when a mouseOver event occurs over an anchor.
You can set the defaultStatus property at any time. You must return true if you want to set the defaultStatus property in the onMouseOver event handler.
In the following example, the statusSetter() function sets both the status and defaultStatus properties in an onMouseOver event handler:
function statusSetter() {
window.defaultStatus = "Click the link for the Netscape home page"
window.status = "Netscape home page"
}
<A HREF="http://www.netscape.com" onMouseOver = "statusSetter(); return true">Netscape</A>
In the previous example, notice that the onMouseOver event handler returns a value of true. You must return true to set status or defaultStatus in an event handler.
A string indicating the default value of a password, text, or textarea object.
1. passwordName.defaultValue 2. textName.defaultValue 3. textareaName.defaultValue
passwordName is either the value of the NAME attribute of a password object or an element in the elements array.
textName is either the value of the NAME attribute of a text object or an element in the elements array.
textareaName is either the value of the NAME attribute of a textarea object or an element in the elements array.
defaultValue initially reflects the value of the VALUE attribute for the password and text objects; for textarea, it initially reflects the value specified between the <TEXTAREA> and </TEXTAREA> tags. Setting defaultValue programatically overrides this initial setting.
You can set the defaultValue property at any time. The display of the related object does not update when you set the defaultValue property, only when you set the value property.
hidden, password, text, textarea
The following function evaluates the defaultValue property of objects on the surfCity form and displays the values in the msgWindow window:
function defaultGetter() {
msgWindow=window.open("")
msgWindow.document.write("hidden.defaultValue is " + document.surfCity.hiddenObj.defaultValue + "<BR>")
msgWindow.document.write("password.defaultValue is " + document.surfCity.passwordObj.defaultValue + "<BR>")
msgWindow.document.write("text.defaultValue is " + document.surfCity.textObj.defaultValue + "<BR>")
msgWindow.document.write("textarea.defaultValue is " + document.surfCity.textareaObj.defaultValue + "<BR>")
msgWindow.document.close()
}
Euler's constant and the base of natural logarithms, approximately 2.718.
Math.E
Because E is a constant, it is a read-only property of Math.
The following example displays Euler's constant:
document.write("Euler's constant is " + Math.E)
An array of objects corresponding to form elements (such as checkbox, radio, and text objects) in source order.
1. formName.elements[index] 2. formName.elements.length
formName is either the name of a form or an element in the forms array.
index is an integer representing an object on a form.
The elements array contains an entry for each object in a form. For example, if a form has a text field and two checkboxes, these elements are reflected as formName.elements[0], formName.elements[1], and formName.elements[2].
The elements array provides a way to reference form objects programatically without using their names. For example, if the first object on the userInfo form is the userName text object, you can evaluate it in either of the following ways:
To obtain the number of elements on a form, use the length property: formName.elements.length. Each radio button in a radio object appears as a separate element in the elements array.
Elements in the elements array are read-only. For example, the statement formName.elements[0]="music" has no effect.
The value of each element in the elements array is the full HTML statement for the object.
See the examples for the name property.
A string specifying the MIME encoding of the form.
formName.encoding
formName is either the name of a form or an element in the forms array.
The encoding property initially reflects the ENCTYPE attribute of the <FORM> tag; however, setting encoding overrides the ENCTYPE attribute.
You can set the encoding property at any time.
Certain values of the encoding property may require specific values for other form properties. See RFC 1867 for more information.
The following function assigns the value of the musicForm encoding property to the variable encodingValue:
function getEncoding() {
var encodingValue
encodingValue=document.musicForm.encoding
}
A string specifying the color of the document foreground text.
document.fgColor
The fgColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Color Values. This property is the JavaScript reflection of the FGCOLOR attribute of the <BODY> tag. The default value of this property is set by the user on the Colors tab of the Preferences dialog box, which is displayed by choosing General Preferences from the Options menu. You cannot set this property after the HTML source has been through layout.
If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072".
The following example sets the color of the foreground to aqua using a string literal:
document.fgColor="aqua"
The following example sets the color of the foreground to aqua using a hexadecimal triplet:
document.fgColor="00FFFF"
An array of objects corresponding to the forms (<FORM> tags) in a document in source order.
1. document.forms[index] 2. document.forms.length
index is an integer representing a form in a document.
The forms array contains an entry for each form object in a document. For example, if a document contains three forms, these forms are reflected as document.forms[0], document.forms[1], and document.forms[2].
You can refer to a form's elements by using the forms array. For example, you would refer to a text object named quantity in the second form as:
document.forms[1].quantityYou would refer to the value property of this text object as:
document.forms[1].quantity.value
To obtain the number of forms in a document, use the length property: document.forms.length.
Elements in the forms array are read-only. For example, the statement document.forms[0]="music" has no effect.
The value of each element in the forms array is
<object nameAttribute>where nameAttribute is the NAME attribute of the form.
The onLoad event handler in the following example displays the name of the first form in an alert dialog box.
<BODY onLoad="alert('You are looking at the ' + document.forms[0] + ' form!')">
If the form name is musicType, the alert displays the following message:
You are looking at the <object musicType> form!
An array of objects corresponding to child frame windows (<FRAME> tag) in source order.
1. [windowReference.]frames[index] 2. [windowReference.]frames.length
windowReference is a variable windowVar from a window definition (see window object), or one of the synonyms top or parent.
index is an integer representing a frame in a parent window.
The frames array contains an entry for each child frame in a window. For example, if a window contains three child frames, these frames are reflected as parent.frames[0], parent.frames[1], and parent.frames[2].
To obtain the number of child frames in a window, use the length property: [windowReference.].frames.length.
Elements in the frames array are read-only. For example, the statement windowReference.frames[0]="frame1" has no effect.
The value of each element in the frames array is
<object nameAttribute>where nameAttribute is the NAME attribute of the frame.
See the examples for the frame object.
A string beginning with a hash mark (#) that specifies an anchor name fragment in the URL.
location.hash
The hash property specifies a portion of the URL.
You can set the hash property at any time, although it is safer to set the href property to change a location. If the hash that you specify cannot be found in the current location, you will get an error.
See RFC 1738 for complete information about the hash.
See the examples for the anchors and href properties.
A string specifying the hostname:port portion of the URL.
location.host
The host property specifies a portion of the URL. The host property is the concatenation of the hostname and port properties, separated by a colon. When the port property is null, the host property is the same as the hostname property.
You can set the host property at any time, although it is safer to set the href property to change a location. If the host that you specify cannot be found in the current location, you will get an error.
See Section 3.1 of RFC 1738 for complete information about the hostname and port.
See the examples for the href property.
A string specifying the domain name or IP address of a network host.
location.hostname
The hostname property specifies a portion of the URL. The hostname property is a substring of the host property. The host property is the concatenation of the hostname and port properties, separated by a colon. When the port property is null, the host property is the same as the hostname property.
You can set the hostname property at any time, although it is safer to set the href property to change a location. If the hostname that you specify cannot be found in the current location, you will get an error.
See Section 3.1 of RFC 1738 for complete information about the hostname.
See the examples for the href property.
A string specifying the entire URL.
location.href
The href property specifies the entire URL. Other location object properties are substrings of the href property. You can set the href property at any time.
See RFC 1738 for complete information about the URL.
In the following example, the window.open statement creates a window called newWindow and loads the specified URL into it. The document.write statements display all the properties of newWindow.location in a window called msgWindow.
newWindow=window.open("http://home.netscape.com/comprod/products/navigator/version_2.0/script/script_info/objects.html#checkbox_object")
msgWindow.document.write("newWindow.location.href = " + newWindow.location.href + "<P>")
msgWindow.document.write("newWindow.location.protocol = " + newWindow.location.protocol + "<P>")
msgWindow.document.write("newWindow.location.host = " + newWindow.location.host + "<P>")
msgWindow.document.write("newWindow.location.hostName = " + newWindow.location.hostName + "<P>")
msgWindow.document.write("newWindow.location.port = " + newWindow.location.port + "<P>")
msgWindow.document.write("newWindow.location.pathname = " + newWindow.location.pathname + "<P>")
msgWindow.document.write("newWindow.location.search = " + newWindow.location.search + "<P>")
msgWindow.document.write("newWindow.location.hash = " + newWindow.location.hash + "<P>")
msgWindow.document.close()
The previous example displays the following output:
newWindow.location.href = http://home.netscape.com/comprod/products/navigator/version_2.0/script/script_info/objects.html#checkbox_object newWindow.location.protocol = http: newWindow.location.host = home.netscape.com newWindow.location.hostName = home.netscape.com newWindow.location.port = newWindow.location.pathname = /comprod/products/navigator/version_2.0/script/script_info/objects.html newWindow.location.search = newWindow.location.hash = #checkbox_object
An integer representing the index of an option in a select object.
selectName.options[indexValue].index
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
indexValue is an integer representing an option in a select object.
The number identifying the position of the option in the selection, starting from zero.
options property
A string representing the date that a document was last modified.
document.lastModified
lastModified is a read-only property.
In the following example, the value of the lastModified property is assigned to a variable called currentDate:
var currentDate = ""
newWindow = window.open("http://www.netscape.com")
currentDate = newWindow.document.lastModified
An integer that specifies a length-related feature of the calling object or array.
When used with objects:
1. formName.length 2. history.length 3. document.formName.radioName.length 4. document.formName.selectName.length 5. stringName.length 6. windowReference.length
When used with array properties:
7. document.anchors.length 8. document.formName.elements.length 9. document.forms.length 10. windowReference.frames.length 11. document.links.length 12. document.formName.selectName.options.length
formName is either the name of a form or an element in the forms array.
radioName is either the value of the NAME attribute of a radio object or an element in the elements array.
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
stringName is any string or a property of an existing object.
windowReference is a valid way of referring to a window, as described in the window object.
The length property is an integer that specifies one of the following:
length is always a read-only property.
For a null string, length is zero. For a select object, the values returned by form 4 and form 12 of the syntax are the same. For a window containing frames, the values returned by form 6 and form 10 of the syntax are the same. For a form object, the values returned by form 1 and form 8 of the syntax are the same.
In the following example, the getChoice() function uses the length property to iterate over every element in the musicType array. musicType is a select element on the musicForm form.
function getChoice() {
for (var i = 0; i < document.musicForm.musicType.length; i++) {
if (document.musicForm.musicType.options[i].selected == true) {
return document.musicForm.musicType.options[i].text
}
}
}
The following example displays 8 in an alert dialog box:
var x="Netscape"
alert("The string length is " + x.length)
A string specifying the color of the document hyperlinks.
document.linkColor
The linkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Color Values. This property is the JavaScript reflection of the LINK attribute of the <BODY> tag. The default value of this property is set by the user on the Colors tab of the Preferences dialog box, which is displayed by choosing General Preferences from the Options menu. You cannot set this property after the HTML source has been through layout.
If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072".
The following example sets the color of document links to aqua using a string literal:
document.linkColor="aqua"
The following example sets the color of document links to aqua using a hexadecimal triplet:
document.linkColor="00FFFF"
An array of objects corresponding to link objects (<A HREF=URL> tags) in source order.
1. document.links[index] 2. document.links.length
index is an integer representing a link in a document.
The links array contains an entry for each link object in a document. For example, if a document contains three link objects, these links are reflected as document.links[0], document.links[1], and document.links[2].
To obtain the number of links in a document, use the length property: document.links.length.
Elements in the links array are read-only. For example, the statement document.links[0]="link1" has no effect.
The following example opens the Netscape home page in the newWindow window. The linkGetter() function uses the links array to display the value of each of its links.
newWindow=window.open("http://www.netscape.com")
function linkGetter() {
msgWindow=window.open("")
for (var i = 0; i < newWindow.document.links.length; i++) {
msgWindow.document.write(newWindow.document.links[i] + "<BR>")
}
}
The natural logarithm of two, approximately 0.693.
Math.LN2
Because LN2 is a constant, it is a read-only property of Math.
The following example displays the natural log of 2:
document.write("The natural log of 2 is " + Math.LN2)
The natural logarithm of ten, approximately 2.302.
Math.LN10
Because LN10 is a constant, it is a read-only property of Math.
The following example displays the natural log of 10:
document.write("The natural log of 10 is " + Math.LN10)
A string specifying the complete URL of the document.
document.location
Do not confuse the location property of the document object with the location object. You cannot change the value of the location property (document.location), but you can change the value of the location object's properties (window.location.propertyName). document.location is a string-valued property that usually matches what window.location is set to when you load the document, but redirection may change it.
location is a read-only property of document.
The following example displays the URL of the current document:
document.write("The current URL is " + document.location)
A string specifying how form field input information is sent to the server.
formName.method
formName is either the name of a form or an element in the forms array.
The method property is a reflection of the METHOD attribute of the <FORM> tag. The method property should evaluate to either "get" or "post".
You can set the method property at any time.
Certain values of the method property may require specific values for other form properties. See RFC 1867 for more information.
The following function assigns the value of the musicForm method property to the variable methodValue:
function getMethod() {
var methodValue
methodValue=document.musicForm.method
}
A string specifying the name of an object.
1. objectName.name 2. radioName[index].name 3. selectName.options.name 4. windowReference.name 5. windowReference.frames.name
objectName is either the value of the NAME attribute of any of the objects listed below or an element in the elements array.
radioName is the value of the NAME attribute of a radio object.
index is an integer representing a radio button in a radio object.
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
windowReference is a valid way of referring to a window, as described in the window object.
The value of the name property differs between the window object and other objects.
The name property for the window object is represented by form 4 and form 5 of the syntax. The name property represents the value of the windowName argument described in the window object syntax. Both forms of the syntax represent the same value.
name is a read-only property.
The name property for all objects except window is represented by forms 1, 2, and 3 of the syntax. For all objects except window, the name property initially reflects the value of the NAME attribute. Changing the name property overrides this setting.
You can set the name property at any time.
The name property is the same for every radio button in a single radio object. Individual radio buttons are referenced by their position in the radio array.
Do not confuse the name property with the label displayed on a button, reset, or submit object. The value property specifies the label for these objects. The name property is not displayed onscreen; it is used to reference the objects programatically.
For a select object, the value specified by form 1 and form 3 of the syntax is the same.
If multiple objects on the same form have the same NAME attribute, an array of the given name is created automatically. Each element in the array represents an individual form object. Elements are indexed starting at 0. For example, if two text elements and a textarea element on the same form have their NAME attribute set to "myField", an array with the elements myField[0], myField[1], and myField[2] is created.
button, checkbox, hidden, password, radio, reset, select, submit, text, textarea, window
In the following example, the valueGetter() function uses a for loop to iterate over the array of elements on the valueTest form. The msgWindow window displays the names of all the elements on the form:
newWindow=window.open("http://www.netscape.com")
function valueGetter() {
msgWindow=window.open("")
for (var i = 0; i < newWindow.document.valueTest.elements.length; i++) {
msgWindow.document.write(newWindow.document.valueTest.elements[i].name + "<BR>")
}
}
In the following example, the first statement creates a window called netscapeWin. The second statement displays the value "netscapeHomePage" in the alert dialog box, because "netscapeHomePage" is the value of the windowName argument of netscapeWin.
netscapeWin=window.open("http://www.netscape.com", "netscapeHomePage")
alert(netscapeWin.name)
For button, reset, and submit:
An array corresponding to options in a select object (<OPTION> tags) in source order.
1. selectName.options 2. selectName.options[index] 3. selectName.options.length 4. selectName.options.options
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
index is an integer representing an option in a select object.
The options array contains an entry for each option in a select object. For example, if a select object named musicStyle contains three options, these options are reflected as musicStyle.options[0], musicStyle.options[1], and musicStyle.options[2].
To obtain the number of options in a select object, use the length property of either the options array or the select object:
1. selectName.length 2. selectName.options.length
The select object has properties that you can access through the options array only. See the select object for a description of these properties.
Even though each element in the options array represents a select option, the value of options[index] is always null. The values represented by selectName.options and selectName.options.options are identical. The values returned by these forms of the syntax represent the full HTML statement for the selectName object.
Elements in the options array are read-only. For example, the statement selectName.options[0]="guitar" has no effect.
See the examples for the defaultSelected property.
The parent property is a synonym for a window that contains frames.
1. parent.propertyName 2. parent.methodName
propertyName is defaultStatus, status, frameName, or frames[index].
frameName and frames[index] are ways to refer to the frames property of window.
methodName is any method associated with the window object.
The parent property does not have a value; it is a synonym that you use to refer to a window object. You can use parent only as shown in the preceding Syntax section; you cannot use window.parent or windowVar.parent.
The parent property refers to the <FRAMESET> window in a <FRAMESET> and <FRAME> relationship.
Child frames within a frameset refer to sibling frames by using "parent" in place of the window name as follows: parent.frameName or parent.frames[index]. For example, if the fourth frame in a set has NAME="homeFrame", sibling frames can refer to that frame using parent.homeFrame or parent.frames[3].
See the examples for the frame object.
A string specifying the url-path portion of the URL.
location.pathname
The pathname property specifies a portion of the URL. The pathname supplies the details of how the specified resource can be accessed.
You can set the pathname property at any time, although it is safer to set the href property to change a location. If the pathname that you specify cannot be found in the current location, you will get an error.
See Section 3.1 of RFC 1738 for complete information about the pathname.
See the examples for the href property.
The ratio of the circumference of a circle to its diameter, approximately 3.1415.
Math.PI
Because PI is a constant, it is a read-only property of Math.
The following example displays the value of pi:
document.write("The value of pi is " + Math.PI)
A string specifying the port number to connect to, if any.
location.port
The port property specifies a portion of the URL. The port property is a substring of the host property. The host property is the concatenation of the hostname and port properties, separated by a colon. When the port property is null, the host property is the same as the hostname property.
You can set the port property at any time, although it is safer to set the href property to change a location. If the port that you specify cannot be found in the current location, you will get an error.
See Section 3.1 of RFC 1738 for complete information about the port.
See the examples for the href property.
A string specifying the beginning of the URL, up to and including the first colon.
location.protocol
The protocol property specifies a portion of the URL. The protocol indicates the access method of the URL. For example, a protocol of "http:" specifies Hypertext Transfer Protocol, and a protocol of "javascript:" specifies JavaScript code.
You can set the protocol property at any time, although it is safer to set the href property to change a location. If the protocol that you specify cannot be found in the current location, you will get an error.
The protocol property represents the scheme name of the URL. See Section 2.1 of RFC 1738 for complete information about the protocol.
See the examples for the href property.
Specifies the URL of the calling document when a user clicks a link.
document.referrer
When a user navigates to a destination document by clicking a link object on a source document, the referrer property contains the URL of the source document. Evaluate the referrer property from the destination document.
referrer is a read-only property.
In the following example, the getReferrer() function is called from the destination document. It returns referrerDocument, the URL of the source document.
function getReferrer() {
var referrerDocument=document.referrer
return referrerDocument
}
A string beginning with a question mark that specifies any query information in the URL.
location.search
The search property specifies a portion of the URL.
You can set the search property at any time, although it is safer to set the href property to change a location. If the search that you specify cannot be found in the current location, you will get an error.
See Section 3.3 of RFC 1738 for complete information about the search.
In the following example, the window.open statement creates a window called newWindow and loads the specified URL into it. The document.write statements display all the properties of newWindow.location in a window called msgWindow.
newWindow=window.open("http://guide-p.infoseek.com/WW/NS/Titles?qt=RFC+1738+&col=WW")
msgWindow.document.write("newWindow.location.href = " + newWindow.location.href + "<P>")
msgWindow.document.write("newWindow.location.protocol = " + newWindow.location.protocol + "<P>")
msgWindow.document.write("newWindow.location.host = " + newWindow.location.host + "<P>")
msgWindow.document.write("newWindow.location.hostName = " + newWindow.location.hostName + "<P>")
msgWindow.document.write("newWindow.location.port = " + newWindow.location.port + "<P>")
msgWindow.document.write("newWindow.location.pathname = " + newWindow.location.pathname + "<P>")
msgWindow.document.write("newWindow.location.search = " + newWindow.location.search + "<P>")
msgWindow.document.write("newWindow.location.hash = " + newWindow.location.hash + "<P>")
msgWindow.document.close()
The previous example displays the following output:
newWindow.location.href = http://guide-p.infoseek.com/WW/NS/Titles?qt=RFC+1738+&col=WW newWindow.location.protocol = http: newWindow.location.host = guide-p.infoseek.com newWindow.location.hostName = guide-p.infoseek.com newWindow.location.port = newWindow.location.pathname = /WW/NS/Titles newWindow.location.search = ?qt=RFC+1738+&col=WW newWindow.location.hash =
A Boolean value specifying the current selection state of an option in a select object.
selectName.options[index].selected
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
index is an integer representing an option in a select object.
If an option in a select object is selected, the value of its selected property is true; otherwise, it is false.
You can set the selected property at any time. The display of the select object updates immediately when you set the selected property.
In general, the selected property is more useful than the selectedIndex property for select objects that are created with the MULTIPLE attribute. With the selected property, you can evaluate every option in the options array to determine multiple selections, and you can select individual options without clearing the selection of other options.
options property
See the examples for the defaultSelected property.
An integer specifying the index of the selected option in a select object.
1. selectName.selectedIndex 2. selectName.options.selectedIndex
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
Options in a select object are indexed in the order in which they are defined, starting with an index of 0. You can set the selectedIndex property at any time. The display of the select object updates immediately when you set the selectedIndex property. Both forms of the syntax specify the same value.
In general, the selectedIndex property is more useful for select objects that are created without the MULTIPLE attribute. If you evaluate selectedIndex when multiple options are selected, the selectedIndex property specifies the index of the first option only. Setting selectedIndex clears any other options that are selected in the select object.
The selected property of the select object's options array is more useful for select objects that are created with the MULTIPLE attribute. With the selected property, you can evaluate every option in the options array to determine multiple selections, and you can select individual options without clearing the selection of other options.
In the following example, the getSelectedIndex() function assigns the selected index in the musicType select object to the variable chosenIndex:
function getSelectedIndex() {
var chosenIndex=""
chosenIndex=document.musicForm.musicType.selectedIndex
}
The previous example assumes that the select object is similar to the following:
<SELECT NAME="musicType"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT>
The self property is a synonym for the current window or frame.
1. self.propertyName 2. self.methodName
propertyName is either the defaultStatus or status property of the window object.
methodName is any method associated with the window object or frame object.
The self property does not have a value; it is a synonym that you use to refer to the current window or frame. You can use self only as shown in the preceding Syntax section; you cannot use window.self or windowVar.self or frameName.self.
Use the self property to disambiguate a window property from a form of the same name. You can also use the self property to make your code more readable.
In the following example, self.status is used to set the status property. This usage disambiguates the status property of a window from a form called "status".
The square root of one-half; equivalently, one over the square root of two, approximately 0.707.
Math.SQRT1_2
Because SQRT1_2 is a constant, it is a read-only property of Math.
The following example displays 1 over the square root of 2:
document.write("1 over the square root of 2 is " + Math.SQRT1_2)
The square root of two, approximately 1.414.
Math.SQRT2
Because SQRT2 is a constant, it is a read-only property of Math.
The following example displays the square root of 2:
document.write("The square root of 2 is " + Math.SQRT2)
Specifies a priority or transient message in the status bar at the bottom of the window, such as the message that appears when a mouseOver event occurs over an anchor.
windowReference.status
windowReference is a valid way of referring to a window, as described in the window object.
Do not confuse the status property with the defaultStatus property. The defaultStatus property reflects the default message displayed in the status bar.
You can set the status property at any time. You must return true if you want to set the status property in the onMouseOver event handler.
Suppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of an anchor to specify a value for the HREF attribute of the anchor dynamically, and the onMouseOver event handler to specify a custom message for the window in the status property:
In the above example, the status property of the window is assigned to the window's self property, as self.status. As this example shows, you must return true to set the status property in the onMouseOver event handler.
For form, a string specifying the name of the window that responses go to after a form has been submitted. For link, a string specifying the name of the window that displays the content of a clicked hypertext link.
1. formName.target 2. linkName.target
formName is either the name of a form or an element in the forms array.
linkName is an element in the links array.
The target property initially reflects the TARGET attribute of the <FORM> and <A> tags; however, setting target overrides these attributes.
The target property cannot be assigned the value of a JavaScript expression or variable; for example, the following statements are not valid:
In the previous example, document.form1.target=winName will cause the target property to have the value "winName", and a window named winName will be created if it does not exist.
You can set the target property at any time.
Certain values of the target property may require specific values for other form properties. See RFC 1867 for more information.
The following example specifies that responses to the musicInfo form are displayed in the "msgWindow" window:
document.musicInfo.target="msgWindow"
For form:
A string specifying the text that follows an <OPTION> tag in a select object.
selectName.options[index].text
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
index is an integer representing an option in a select object.
The text property initially reflects the text that follows an <OPTION> tag in a select object.
You can set the text property at any time; however, the following effects result:
Be careful if you change the text property. If you evaluate the property after you change it, the property contains the new value, not the value that is displayed onscreen.
options property
In the following example, the getChoice() function returns the value of the text property for the selected option. The for loop evaluates every option in the musicType select object. The if statement finds the option that is selected.
function getChoice() {
for (var i = 0; i < document.musicForm.musicType.length; i++) {
if (document.musicForm.musicType.options[i].selected == true) {
return document.musicForm.musicType.options[i].text
}
}
}
The previous example assumes that the select object is similar to the following:
<SELECT NAME="musicType"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT>
A string representing the title of a document.
document.title
The title property is a reflection of the value specified within the <TITLE> and </TITLE> tags. If a document does not have a title, the title property is null.
title is a read-only property.
In the following example, the value of the title property is assigned to a variable called docTitle:
var docTitle = ""
newWindow = window.open("http://www.netscape.com")
docTitle = newWindow.document.title
The top property is a synonym for the top-most Navigator window, which is a "document window" or "Web Browser window."
1. top.propertyName 2. top.methodName
propertyName is defaultStatus, status, frameName, or frames[index].
frameName and frames[index] are ways to refer to the frames property of window.
methodName is any method associated with the window object.
The top property does not have a value; it is a synonym that you use to refer to a window object. You can use top only as shown in the preceding Syntax section; you cannot use window.top or windowVar.top.
The top property refers to the top-most window that has opened other windows. Use the top property to refer to this ancestor window when you are manipulating multiple windows at the same time.
In the following example, the netscapeInfo() function opens a window to display the JavaScript documentation and another window to display the Netscape home page, then closes the calling window.
function netscapeInfo() {
netscapePage=window.open("http://www.netscape.com")
javaPage=window.open("http://home.netscape.com/comprod/products/navigator/version_2.0/script/script_info/")
top.close()
}
A string representing the value of the user-agent header sent in the HTTP protocol from client to server.
navigator.userAgent
Servers use the value sent in the user-agent header to identify the client.
userAgent is a read-only property.
The following example displays userAgent information for the Navigator:
document.write("The value of navigator.userAgent is " + navigator.userAgent)
This example displays information such as the following:
The value of navigator.userAgent is Mozilla/2.0b5 (Win16; I)
A string that is related to the VALUE attribute of its object.
1. objectName.value 2. radioName[index].value 3. selectName.options.[index].value
objectName is either the value of the NAME attribute of a hidden, password, text, textarea, button, reset, submit or checkbox object or an element in the elements array.
radioName is the value of the NAME attribute of a radio object.
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
index is an integer representing a radio button in a radio object or an option in a select object.
The value property differs for every object.
You can set the value property at any time. The display of the text and textarea objects updates immediately when you set the value property; the display of the password object remains as asterisks.
When a VALUE attribute is specified in HTML, the value property is a string that reflects it. This string is displayed on the face of the button.
When a VALUE attribute is not specified in HTML, the value property differs for each object:
These strings are displayed on the faces of the buttons.
value is a read-only property.
Do not confuse the value property with the name property. The name property is not displayed onscreen; it is used to reference the objects programatically.
The value property is a string that initially reflects the VALUE attribute. The value of this property can change when a program modifies it. The value property is not displayed onscreen, but is returned to the server if the select option is selected.
You can set the value property at any time.
Do not confuse the value property with the selection state of the select object or the text that is displayed as an option. The selected and selectedIndex properties determine which options are selected, and the defaultSelected property determines the default selection state. The text that is displayed in each option is specified by the text property.
When a VALUE attribute is specified in HTML, the value property is a string that reflects it. When a VALUE attribute is not specified in HTML, the value property is a string that evaluates to "on". The value property is not displayed onscreen, but is returned to the server if the radio button or checkbox is selected.
You can set the value property at any time.
Do not confuse the value property with the selection state of the object or the text that is displayed next to each checkbox and radio button. The checked property determines the selection state of the object, and the defaultChecked property determines the default selection state. The text that is displayed is specified following the <INPUT TYPE="checkbox"> or the <INPUT TYPE="radio"> tag.
button, checkbox, hidden, password, radio, reset, submit, text, textarea objects
options property
The following function evaluates the value property of a group of buttons and displays it in the msgWindow window:
function valueGetter() {
msgWindow=window.open("")
msgWindow.document.write("submitButton.value is " + document.valueTest.submitButton.value + "<BR>")
msgWindow.document.write("resetButton.value is " + document.valueTest.resetButton.value + "<BR>")
msgWindow.document.write("helpButton.value is " + document.valueTest.helpButton.value + "<BR>")
msgWindow.document.close()
This example displays the following values:
Query Submit Reset Help
The previous example assumes the buttons have been defined as follows
<INPUT TYPE=submit NAME="submitButton"> <INPUT TYPE=reset NAME="resetButton"> <INPUT TYPE=button NAME="helpButton" VALUE="Help">
The following function evaluates the value property of a group of radio buttons and displays it in the msgWindow window:
function valueGetter() {
msgWindow=window.open("")
for (var i = 0; i < document.valueTest.radioObj.length; i++) {
msgWindow.document.write("The value of radioObj[" + i + "] is " + document.valueTest.radioObj[i].value +"<BR>")
}
x.document.close()
}
This example displays the following values:
on on on on
The previous example assumes the buttons have been defined as follows
<BR><INPUT TYPE="radio" NAME="radioObj">R&B <BR><INPUT TYPE="radio" NAME="radioObj" CHECKED>Soul <BR><INPUT TYPE="radio" NAME="radioObj">Rock and Roll <BR><INPUT TYPE="radio" NAME="radioObj">Blues
For hidden, password, text, and textarea:
For button, reset, and submit:
For options property of select:
For checkbox and radio:
A string specifying the color of visited links.
document.vlinkColor
The vlinkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Color Values. This property is the JavaScript reflection of the VLINK attribute of the <BODY> tag. The default value of this property is set by the user on the Colors tab of the Preferences dialog box, which is displayed by choosing General Preferences from the Options menu. You cannot set this property after the HTML source has been through layout.
If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072".
The following example sets the color of visited links to aqua using a string literal:
document.vlinkColor="aqua"
The following example sets the color of active links to aqua using a hexadecimal triplet:
document.vlinkColor="00FFFF"
The window property is a synonym for the current window or frame.
1. window.propertyName 2. window.methodName
propertyName is the defaultStatus or status property of the window object.
methodName is any method associated with the window object or frame object.
The window property does not have a value; it is a synonym that you use to refer to the current window or frame. You can use window only as shown in the preceding Syntax section; you cannot use window.window or windowVar.window or frameName.window.
Use the window property to disambiguate a property of the window object from a form of the same name. You can also use the window property to make your code more readable.
In the following example, window.status is used to set the status property. This usage disambiguates the status property of a window from a form called "status".