Properties

The following properties are available in JavaScript:
  • action
  • alinkColor
  • anchors
  • appCodeName
  • appName
  • appVersion
  • bgColor
  • checked
  • cookie
  • defaultChecked
  • defaultSelected
  • defaultStatus
  • defaultValue
  • E
  • elements
  • encoding
  • fgColor
  • forms
  • frames
  • hash
  • host
  • hostname
  • href
  • index
  • lastModified
  • length
  • linkColor
  • links
  • LN2
  • LN10
  • location
  • method
  • name
  • options
  • parent
  • pathname
  • PI
  • port
  • protocol
  • referrer
  • search
  • selected
  • selectedIndex
  • self
  • SQRT1_2
  • SQRT2
  • status
  • target
  • text
  • title
  • top
  • userAgent
  • value
  • vlinkColor
  • window

  • action property

    A string specifying the URL of the server to which form field input information is sent.

    Syntax

    formName.action

    formName is either the name of a form or an element in the forms array.

    Description

    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.

    Applies to

    form

    Examples

    The following example sets the action property of the musicForm form to the value of the variable urlName:

    document.musicForm.action=urlName

    See also

  • encoding, method, target properties

    alinkColor property

    A string specifying the color of an active link (after mouse-button down, but before mouse-button up).

    Syntax

    document.alinkColor

    Description

    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".

    Applies to

    document

    Examples

    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"
    

    See also

  • bgColor, fgColor, linkColor, and vlinkColor properties

    anchors property

    An array of objects corresponding to named anchors (<A NAME="anchorName"> tags) in source order.

    Syntax

    1. document.anchors[index]
    2. document.anchors.length
    

    index is an integer representing an anchor in a document.

    Description

    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.

    Applies to

    document

    Examples

    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:

    <HTML> <HEAD> <TITLE>Links and Anchors: Window 1</TITLE> </HEAD> <BODY> <SCRIPT> window2=open("link2.html","secondLinkWindow","scrollbars=yes,width=250, height=400") function linkToWindow(num) { if (window2.document.anchors.length > num) { window2.location.hash=num } else { alert("Anchor does not exist!") } } </SCRIPT> <B>Links and Anchors</B> <FORM> <P>Click a button to display that anchor in window #2 <P><INPUT TYPE="button" VALUE="0" NAME="link0_button" onClick="linkToWindow(this.value)"> <INPUT TYPE="button" VALUE="1" NAME="link0_button" onClick="linkToWindow(this.value)"> <INPUT TYPE="button" VALUE="2" NAME="link0_button" onClick="linkToWindow(this.value)"> <INPUT TYPE="button" VALUE="3" NAME="link0_button" onClick="linkToWindow(this.value)"> <INPUT TYPE="button" VALUE="4" NAME="link0_button" onClick="linkToWindow(this.value)"> </FORM> </BODY> </HTML>

    LINK2.HTML, which contains the anchors, contains the following code:

    <HTML> <HEAD> <TITLE>Links and Anchors: Window 2</TITLE> </HEAD> <BODY> <A NAME="0"><B>Some numbers</B> (Anchor 0)</A> <LI>one <LI>two <LI>three <LI>four <LI>five <LI>six <LI>seven <LI>eight <LI>nine <P><A NAME="1"><B>Some colors</B> (Anchor 1)</A> <LI>red <LI>orange <LI>yellow <LI>green <LI>blue <LI>purple <LI>brown <LI>black <P><A NAME="2"><B>Some music types</B> (Anchor 2)</A> <LI>R&B <LI>Jazz <LI>Soul <LI>Reggae <LI>Rock <LI>Country <LI>Classical <LI>Opera <P><A NAME="3"><B>Some countries</B> (Anchor 3)</A> <LI>Afghanistan <LI>Brazil <LI>Canada <LI>Finland <LI>India <LI>Italy <LI>Japan <LI>Kenya <LI>Mexico <LI>Nigeria </BODY> </HTML>

    See also

  • links, length properties
  • anchor, link objects

    appCodeName property

    A string specifying the code name of the browser.

    Syntax

    navigator.appCodeName

    Description

    appCodeName is a read-only property.

    Applies to

    navigator

    Examples

    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

    See also

  • appName, appVersion, userAgent properties

    appName property

    A string specifying the name of the browser.

    Syntax

    navigator.appName

    Description

    appName is a read-only property.

    Applies to

    navigator

    Examples

    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

    See also

  • appVersion, appCodeName, userAgent properties

    appVersion property

    A string specifying version information for the Navigator.

    Syntax

    navigator.appVersion

    Description

    The appVersion property specifies version information in the following format:

    releaseNumber (platform; country)

    The values contained in this format are the following:

  • releaseNumber is the version number of the Navigator. For example, "2.0b4" specifies Navigator 2.0, beta 4.
  • platform is the platform upon which the Navigator is running. For example, "Win16" specifies a 16-bit version of Windows such as Windows 3.11.
  • country is either "I" for the international release, or "U" for the domestic U.S. release. The domestic release has a stronger encryption feature than the international release.

    appVersion is a read-only property.

    Applies to

    navigator

    Examples

    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)

    See also

  • appName, appCodeName, userAgent properties

    bgColor property

    A string specifying the color of the document background.

    Syntax

    document.bgColor

    Description

    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".

    Applies to

    document

    Examples

    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"
    

    See also

  • alinkColor, fgColor, linkColor, and vlinkColor properties

    checked property

    A Boolean value specifying the selection state of a checkbox object or radio button.

    Syntax

    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.

    Description

    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.

    Applies to

    checkbox, radio

    Examples

    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
          }
       }
    }
    

    See also

  • defaultChecked property

    cookie property

    String value of a cookie, which is a small piece of information stored by the Navigator in the cookies.txt file.

    Syntax

    document.cookie

    Description

    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.

    Applies to

    document

    Examples

    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.

    See also

  • hidden object

    defaultChecked property

    A Boolean value indicating the default selection state of a checkbox or radio button.

    Syntax

    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.

    Description

    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.

    Applies to

    checkbox, radio

    Examples

    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
          }
       }
    }
    

    See also

  • checked property

    defaultSelected property

    A Boolean value indicating the default selection state of an option in a select object.

    Syntax

    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.

    Description

    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.

    Applies to

    options property

    Examples

    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>
    

    See also

  • index, selected, selectedIndex properties

    defaultStatus property

    The default message displayed in the status bar at the bottom of the window.

    Syntax

    windowReference.defaultStatus

    windowReference is a valid way of referring to a window, as described in the window object.

    Description

    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.

    Applies to

    window

    Examples

    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.

    See also

  • status property

    defaultValue property

    A string indicating the default value of a password, text, or textarea object.

    Syntax

    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.

    Description

    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.

    Applies to

    hidden, password, text, textarea

    Examples

    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()
    }
    

    See also

  • value property

    E property

    Euler's constant and the base of natural logarithms, approximately 2.718.

    Syntax

    Math.E

    Description

    Because E is a constant, it is a read-only property of Math.

    Applies to

    Math

    Examples

    The following example displays Euler's constant:

    document.write("Euler's constant is " + Math.E)

    See also

  • LN2, LN10, PI, SQRT1_2, SQRT2 properties

    elements property

    An array of objects corresponding to form elements (such as checkbox, radio, and text objects) in source order.

    Syntax

    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.

    Description

    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:

  • userInfo.userName.value
  • userInfo.elements[0].value

    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.

    Applies to

    form

    Examples

    See the examples for the name property.


    encoding property

    A string specifying the MIME encoding of the form.

    Syntax

    formName.encoding

    formName is either the name of a form or an element in the forms array.

    Description

    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.

    Applies to

    form

    Examples

    The following function assigns the value of the musicForm encoding property to the variable encodingValue:

    function getEncoding() {
       var encodingValue
       encodingValue=document.musicForm.encoding
    }
    

    See also

  • action, method, target properties

    fgColor property

    A string specifying the color of the document foreground text.

    Syntax

    document.fgColor

    Description

    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".

    Applies to

    document

    Examples

    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"
    

    See also

  • alinkColor, bgColor, linkColor, and vlinkColor properties

    forms property

    An array of objects corresponding to the forms (<FORM> tags) in a document in source order.

    Syntax

    1. document.forms[index]
    2. document.forms.length
    

    index is an integer representing a form in a document.

    Description

    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].quantity
    
    You 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.

    Applies to

    document

    Examples

    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!

    See also

  • length property

    frames property

    An array of objects corresponding to child frame windows (<FRAME> tag) in source order.

    Syntax

    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.

    Description

    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.

    Applies to

    window

    Examples

    See the examples for the frame object.

    See also

  • length property

    hash property

    A string beginning with a hash mark (#) that specifies an anchor name fragment in the URL.

    Syntax

    location.hash

    Description

    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.

    Applies to

    location

    Examples

    See the examples for the anchors and href properties.

    See also

  • host, hostname, href, pathname, port, protocol, search properties

    host property

    A string specifying the hostname:port portion of the URL.

    Syntax

    location.host

    Description

    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.

    Applies to

    location

    Examples

    See the examples for the href property.

    See also

  • hash, hostname, href, pathname, port, protocol, search properties

    hostname property

    A string specifying the domain name or IP address of a network host.

    Syntax

    location.hostname

    Description

    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.

    Applies to

    location

    Examples

    See the examples for the href property.

    See also

  • hash, host, href, pathname, port, protocol, search properties

    href property

    A string specifying the entire URL.

    Syntax

    location.href

    Description

    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.

    Applies to

    location

    Examples

    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
    

    See also

  • hash, host, hostname, pathname, port, protocol, search properties

    index property

    An integer representing the index of an option in a select object.

    Syntax

    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.

    Description

    The number identifying the position of the option in the selection, starting from zero.

    Applies to

    options property

    See also

  • defaultSelected, selected, selectedIndex properties

    lastModified property

    A string representing the date that a document was last modified.

    Syntax

    document.lastModified

    Description

    lastModified is a read-only property.

    Applies to

    document

    Examples

    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
    

    length property

    An integer that specifies a length-related feature of the calling object or array.

    Syntax

    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.

    Description

    The length property is an integer that specifies one of the following:

  • The number of elements on a form (form 1 of the syntax).
  • The number of entries in a history object (form 2 of the syntax).
  • The number of radio buttons in a radio object (form 3 of the syntax).
  • The number of options in a select object (form 4 of the syntax).
  • The length of a string object (form 5 of the syntax).
  • The number of frames in a parent window (form 6 of the syntax).
  • The number of entries in one of the array properties (all other syntax forms).

    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.

    Applies to

  • history, radio, select, string, window objects
  • anchors, elements, forms, frames, links, options properties

    Examples

    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)
    

    linkColor property

    A string specifying the color of the document hyperlinks.

    Syntax

    document.linkColor

    Description

    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".

    Applies to

    document

    Examples

    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"
    

    See also

  • alinkColor, bgColor, fgColor, and vlinkColor properties

    links property

    An array of objects corresponding to link objects (<A HREF=URL> tags) in source order.

    Syntax

    1. document.links[index]
    2. document.links.length
    

    index is an integer representing a link in a document.

    Description

    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.

    Applies to

    document

    Examples

    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>")
       }
    }
    

    See also

  • anchors, length properties

    LN2 property

    The natural logarithm of two, approximately 0.693.

    Syntax

    Math.LN2

    Description

    Because LN2 is a constant, it is a read-only property of Math.

    Applies to

    Math

    Examples

    The following example displays the natural log of 2:

    document.write("The natural log of 2 is " + Math.LN2)

    See also

  • E, LN10, PI, SQRT1_2, SQRT2 properties

    LN10 property

    The natural logarithm of ten, approximately 2.302.

    Syntax

    Math.LN10

    Description

    Because LN10 is a constant, it is a read-only property of Math.

    Applies to

    Math

    Examples

    The following example displays the natural log of 10:

    document.write("The natural log of 10 is " + Math.LN10)

    See also

  • E, LN2, PI, SQRT1_2, SQRT2 properties

    location property

    A string specifying the complete URL of the document.

    Syntax

    document.location

    Description

    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.

    Applies to

    document

    Examples

    The following example displays the URL of the current document:

    document.write("The current URL is " + document.location)
    

    See also

  • location object

    method property

    A string specifying how form field input information is sent to the server.

    Syntax

    formName.method

    formName is either the name of a form or an element in the forms array.

    Description

    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.

    Applies to

    form

    Examples

    The following function assigns the value of the musicForm method property to the variable methodValue:

    function getMethod() {
       var methodValue
       methodValue=document.musicForm.method
    }
    

    See also

  • action, encoding, target properties

    name property

    A string specifying the name of an object.

    Syntax

    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.

    Description

    The value of the name property differs between the window object and other objects.

    window object

    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.

    All other objects

    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.

    Applies to

    button, checkbox, hidden, password, radio, reset, select, submit, text, textarea, window

    Examples

    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)
    

    See also

    For button, reset, and submit:

  • value property

    options property

    An array corresponding to options in a select object (<OPTION> tags) in source order.

    Syntax

    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.

    Description

    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.

    Applies to

    select

    Examples

    See the examples for the defaultSelected property.

    See also

  • length property

    parent property

    The parent property is a synonym for a window that contains frames.

    Syntax

    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.

    Description

    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].

    Applies to

    frame, window

    Examples

    See the examples for the frame object.


    pathname property

    A string specifying the url-path portion of the URL.

    Syntax

    location.pathname

    Description

    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.

    Applies to

    location

    Examples

    See the examples for the href property.

    See also

  • hash, host, hostname, href, port, protocol, search properties

    PI property

    The ratio of the circumference of a circle to its diameter, approximately 3.1415.

    Syntax

    Math.PI

    Description

    Because PI is a constant, it is a read-only property of Math.

    Applies to

    Math

    Examples

    The following example displays the value of pi:

    document.write("The value of pi is " + Math.PI)

    See also

  • E, LN2, LN10, SQRT1_2, SQRT2 properties

    port property

    A string specifying the port number to connect to, if any.

    Syntax

    location.port

    Description

    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.

    Applies to

    location

    Examples

    See the examples for the href property.

    See also

  • hash, host, hostname, href, pathname, protocol, search properties

    protocol property

    A string specifying the beginning of the URL, up to and including the first colon.

    Syntax

    location.protocol

    Description

    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.

    Applies to

    location

    Examples

    See the examples for the href property.

    See also

  • hash, host, hostname, href, pathname, port, search properties

    referrer property

    Specifies the URL of the calling document when a user clicks a link.

    Syntax

    document.referrer

    Description

    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.

    Applies to

    document

    Examples

    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
    }
    

    search property

    A string beginning with a question mark that specifies any query information in the URL.

    Syntax

    location.search

    Description

    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.

    Applies to

    location

    Examples

    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 = 
    

    See also

  • hash, host, hostname, href, pathname, port, protocol properties

    selected property

    A Boolean value specifying the current selection state of an option in a select object.

    Syntax

    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.

    Description

    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.

    Applies to

    options property

    Examples

    See the examples for the defaultSelected property.

    See also

  • defaultSelected, index, selectedIndex properties

    selectedIndex property

    An integer specifying the index of the selected option in a select object.

    Syntax

    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.

    Description

    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.

    Applies to

    select

    Examples

    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>
    

    See also

  • defaultSelected, index, selected properties

    self property

    The self property is a synonym for the current window or frame.

    Syntax

    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.

    Description

    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.

    Applies to

    frame, window

    Examples

    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".

    <A HREF="" onClick="this.href=pickRandomURL()" onMouseOver="self.status='Pick a random URL' ; return true"> Go!</A>

    See also

  • window property

    SQRT1_2 property

    The square root of one-half; equivalently, one over the square root of two, approximately 0.707.

    Syntax

    Math.SQRT1_2

    Description

    Because SQRT1_2 is a constant, it is a read-only property of Math.

    Applies to

    Math

    Examples

    The following example displays 1 over the square root of 2:

    document.write("1 over the square root of 2 is " + Math.SQRT1_2)

    See also

  • E, LN2, LN10, PI, SQRT2 properties

    SQRT2 property

    The square root of two, approximately 1.414.

    Syntax

    Math.SQRT2

    Description

    Because SQRT2 is a constant, it is a read-only property of Math.

    Applies to

    Math

    Examples

    The following example displays the square root of 2:

    document.write("The square root of 2 is " + Math.SQRT2)

    See also

  • E, LN2, LN10, PI, SQRT1_2 properties

    status property

    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.

    Syntax

    windowReference.status

    windowReference is a valid way of referring to a window, as described in the window object.

    Description

    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.

    Applies to

    window

    Examples

    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:

    <A HREF="" onClick="this.href=pickRandomURL()" onMouseOver="self.status='Pick a random URL'; return true"> Go!</A>

    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.

    See also

  • defaultStatus property

    target property

    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.

    Syntax

    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.

    Description

    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:

    document.form1.target=parent.frame2 document.form1.target=window2.frame2 <A HREF=doc3.html#musicTypes TARGET="window2.frame2">Music types</A> var winName="window2" document.form1.target=winName

    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.

    Applies to

    form, link

    Examples

    The following example specifies that responses to the musicInfo form are displayed in the "msgWindow" window:

    document.musicInfo.target="msgWindow"

    See also

    For form:

  • action, encoding, method properties

    text property

    A string specifying the text that follows an <OPTION> tag in a select object.

    Syntax

    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.

    Description

    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:

  • The value of the property changes.
  • The text displayed by the option in the select object does not change.

    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.

    Applies to

    options property

    Examples

    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>
    

    title property

    A string representing the title of a document.

    Syntax

    document.title

    Description

    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.

    Applies to

    document

    Examples

    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
    

    top property

    The top property is a synonym for the top-most Navigator window, which is a "document window" or "Web Browser window."

    Syntax

    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.

    Description

    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.

    Applies to

    frame, window

    Examples

    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()
    }
    

    userAgent property

    A string representing the value of the user-agent header sent in the HTTP protocol from client to server.

    Syntax

    navigator.userAgent

    Description

    Servers use the value sent in the user-agent header to identify the client.

    userAgent is a read-only property.

    Applies to

    navigator

    Examples

    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)

    See also

  • appName, appVersion, appCodeName properties

    value property

    A string that is related to the VALUE attribute of its object.

    Syntax

    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.

    Description

    The value property differs for every object.

    hidden, password, text, and textarea objects

    The value property is a string that initially reflects the VALUE attribute. This string is displayed in the text and textarea fields, and is represented by asterisks in the password object field. The value of this property changes when a user or a program modifies the field.

    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.

    button, reset, and submit objects

    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:

  • For button, it is an empty string
  • For reset, it is the string "Reset"
  • For submit, it is the string "Submit Query"

    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.

    options property of the select object

    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.

    checkbox and radio objects

    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.

    Applies to

    button, checkbox, hidden, password, radio, reset, submit, text, textarea objects

    options property

    Examples

    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
    

    See also

    For hidden, password, text, and textarea:

  • defaultValue property

    For button, reset, and submit:

  • name property

    For options property of select:

  • defaultSelected, selected, selectedIndex, text properties

    For checkbox and radio:

  • checked, defaultChecked properties

    vlinkColor property

    A string specifying the color of visited links.

    Syntax

    document.vlinkColor

    Description

    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".

    Applies to

    document

    Examples

    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"
    

    See also

  • alinkColor, bgColor, fgColor, and linkColor properties

    window property

    The window property is a synonym for the current window or frame.

    Syntax

    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.

    Description

    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.

    Applies to

    frame, window

    Examples

    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".

    <A HREF="" onClick="this.href=pickRandomURL()" onMouseOver="window.status='Pick a random URL' ; return true"> Go!</A>

    See also

  • self property