Alphabetical list

The following objects, methods, properties, and event handlers are available in JavaScript:
  • abs
  • acos
  • action
  • alert
  • alinkColor
  • anchor
  • anchor (anchors array)
  • anchors
  • appCodeName
  • appName
  • appVersion
  • asin
  • atan
  • back
  • bgColor
  • big
  • blink
  • blur
  • bold
  • button
  • ceil
  • charAt
  • checkbox
  • checked
  • clear
  • clearTimeout
  • click
  • close (document)
  • close (window)
  • confirm
  • cookie
  • cos
  • Date
  • defaultChecked
  • defaultSelected
  • defaultStatus
  • defaultValue
  • document
  • E
  • elements array
  • elements
  • encoding
  • escape
  • eval
  • exp
  • fgColor
  • fixed
  • floor
  • focus
  • fontcolor
  • fontsize
  • form (forms array)
  • forms
  • forward
  • frame (frames array)
  • frames
  • getDate
  • getDay
  • getHours
  • getMinutes
  • getMonth
  • getSeconds
  • getTime
  • getTimezoneOffset
  • getYear
  • go
  • hash
  • hidden
  • history
  • host
  • hostname
  • href
  • index
  • indexOf
  • isNaN
  • italics
  • lastIndexOf
  • lastModified
  • length
  • link
  • link (links array)
  • linkColor
  • links
  • LN2
  • LN10
  • location
  • location
  • log
  • LOG2E
  • LOG10E
  • Math
  • max
  • method
  • min
  • name
  • navigator
  • onBlur
  • onChange
  • onClick
  • onFocus
  • onLoad
  • onMouseOver
  • onSelect
  • onSubmit
  • onUnload
  • open (document)
  • open (window)
  • options
  • parent
  • parse
  • parseFloat
  • parseInt
  • password
  • pathname
  • PI
  • port
  • pow
  • prompt
  • protocol
  • radio
  • random
  • referrer
  • reset
  • round
  • search
  • select
  • select (options array)
  • selected
  • selectedIndex
  • self
  • setDate
  • setHours
  • setMinutes
  • setMonth
  • setSeconds
  • setTime
  • setTimeout
  • setYear
  • sin
  • small
  • sqrt
  • SQRT1_2
  • SQRT2
  • status
  • strike
  • string
  • sub
  • submit
  • submit
  • substring
  • sup
  • tan
  • target
  • text
  • text
  • textarea
  • title
  • toGMTString
  • toLocaleString
  • toLowerCase
  • top
  • toUpperCase
  • unescape
  • userAgent
  • UTC
  • value
  • vlinkColor
  • window
  • window
  • write
  • writeln

  • abs method

    Returns the absolute value of a number.

    Syntax

    Math.abs(number)

    number is any numeric expression or a property of an existing object.

    Method of

    Math

    Examples

    In the following example, the user enters a number in the first text box and presses the Calculate button to display the absolute value of the number.

    <FORM>
    <P>Enter a number:
    <INPUT TYPE="text" NAME="absEntry">
    
    <P>The absolute value is:
    <INPUT TYPE="text" NAME="result">
    
    <P>
    <INPUT TYPE="button" VALUE="Calculate"
       onClick="form.result.value = Math.abs(form.absEntry.value)">
    
    </FORM>
    

    acos method

    Returns the arc cosine (in radians) of a number.

    Syntax

    Math.acos(number)

    number is a numeric expression between -1 and 1, or a property of an existing object.

    Method of

    Math

    Description

    The acos method returns a numeric value between 0 and pi radians. If the value of number is outside the suggested range, the return value is always 0.

    Examples

    // Displays the value 0
    document.write("The arc cosine of 1 is " + Math.acos(1))
    
    // Displays the value 3.141592653589793
    document.write("<P>The arc cosine of -1 is " + Math.acos(-1))
    
    // Displays the value 0
    document.write("<P>The arc cosine of 2 is " + Math.acos(2))
    

    See also

  • asin, atan, cos, sin, tan methods

    action property

    A string specifying a destination URL for form data that is submitted.

    Syntax

    formName.action

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

    Property of

    form

    Description

    The action property is a reflection of the ACTION attribute of the <FORM> tag. Each section of a URL contains different information. See the location object for a description of the URL components.

    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.

    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

    alert method

    Displays an Alert dialog box with a message and an OK button.

    Syntax

    alert("message")

    message is any string or a property of an existing object.

    Method of

    window

    Description

    Use the alert method to display a message that does not require a user decision. The message argument specifies a message that the dialog box contains.

    Although alert is a method of the window object, you do not need to specify a windowReference when you call it. For example, windowReference.alert() is unnecessary.

    Examples

    In the following example, the testValue() function checks the name entered by a user in the text object of a form to make sure that it is no more than eight characters in length. This example uses the alert method to prompt the user to enter a valid value.

    function testValue(textElement) {
       if (textElement.length > 8) {
          alert("Please enter a name that is 8 characters or less")
       }
    }
    You can call the testValue() function in the onBlur event handler of a form's text object, as shown in the following example:
    Name: <INPUT TYPE="text" NAME="userName"
       onBlur="testValue(userName.value)">

    See also

  • confirm, prompt methods

    alinkColor property

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

    Syntax

    document.alinkColor

    Property of

    document

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

    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

    anchor method

    Creates an HTML anchor that is used as a hypertext target.

    Syntax

    text.anchor(nameAttribute)

    text is any string or a property of an existing object.
    nameAttribute is any string or a property of an existing object.

    Method of

    string

    Description

    Use the anchor method with the write or writeln methods to programatically create and display an anchor in a document. Create the anchor with the anchor method, then call write or writeln to display the anchor in a document.

    In the syntax, the text string represents the literal text that you want the user to see. The nameAttribute string represents the NAME attribute of the <A> tag.

    Anchors created with the anchor method become elements in the anchors array. See the anchor object for information about the anchors array.

    Examples

    The following example opens the msgWindow window and creates an anchor for the Table of Contents:

    var myString="Table of Contents" msgWindow=window.open("","displayWindow") msgWindow.document.writeln(myString.anchor("contents_anchor")) msgWindow.document.close()

    The previous example produces the same output as the following HTML:

    <A NAME="contents_anchor">Table of Contents</A>

    See also

  • link method

    anchor object (anchors array)

    A piece of text that can be the target of a hypertext link.

    Syntax

    To define an anchor, use standard HTML syntax:

    <A [HREF=locationOrURL]
       NAME="anchorName"
       [TARGET="windowName"]>
       anchorText
    </A>
    
    HREF=locationOrURL identifies a destination anchor or URL. If this attribute is present, the anchor object is also a link object. See link for details.
    NAME="anchorName" specifies a tag that becomes an available hypertext target within the current document.
    TARGET="windowName" specifies the window that the link is loaded into. This attribute is meaningful only if HREF=locationOrURL is present. See link for details.
    anchorText specifies the text to display at the anchor.

    You can also define an anchor using the anchor method.

    Property of

  • document

    Description

    If an anchor object is also a link object, the object has entries in both the anchors and links arrays.

    The anchors array

    You can reference the anchor objects in your code by using the anchors array. This array contains an entry for each <A> tag containing a NAME attribute in a document in source order. For example, if a document contains three named anchors, these anchors are reflected as document.anchors[0], document.anchors[1], and document.anchors[2].

    To use the anchors array:

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

    index is an integer representing an anchor in a document.

    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.

    Properties

    The anchors object has no properties. The anchors array has the following properties:

  • length reflects the number of named anchors in a document

    Methods

  • None.

    Event handlers

  • None.

    Examples

    Example 1: an anchor. The following example defines an anchor for the text "Welcome to JavaScript".

    <A NAME="javascript_intro"><H2>Welcome to JavaScript</H2></A>

    If the preceding anchor is in a file called intro.html, a link in another file could define a jump to the anchor as follows:

    <A HREF="intro.html#javascript_intro">Introduction</A>

    Example 2: anchors array. 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

  • link object
  • anchor method

    anchors property

    An array of objects corresponding to named anchors in source order. See anchor object.


    appCodeName property

    A string specifying the code name of the browser.

    Syntax

    navigator.appCodeName

    Property of

    navigator

    Description

    appCodeName is a read-only property.

    Examples

    The following example displays the value of the appCodeName property:

    document.write("The value of navigator.appCodeName is " +
       navigator.appCodeName)

    For Navigator 2.0, this displays 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

    Property of

    navigator

    Description

    appName is a read-only property.

    Examples

    The following example displays the value of the appName property:

    document.write("The value of navigator.appName is " +
       navigator.appName)

    For Navigator 2.0, this displays 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

    Property of

    navigator

    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.

    Examples

    Example 1. The following example displays version information for the Navigator:

    document.write("The value of navigator.appVersion is " +
       navigator.appVersion)

    For Navigator 2.0 on Windows 95, this displays the following:

    The value of navigator.appVersion is 2.0 (Win95, I)

    Example 2. The following example populates a textarea object with newline characters separating each line. Because the newline character varies from platform to platform, the example tests the appVersion property to determine whether the user is running Windows (appVersion contains "Win" for all versions of Windows). If the user is running Windows, the newline character is set to \r\n; otherwise, it's set to \n, which is the newline character for Unix and Macintosh.

    <SCRIPT> var newline=null function populate(textareaObject){ if (navigator.appVersion.lastIndexOf('Win') != -1) newline="\r\n" else newline="\n" textareaObject.value="line 1" + newline + "line 2" + newline + "line 3" } </SCRIPT> <FORM NAME="form1"> <BR><TEXTAREA NAME="testLines" ROWS=8 COLS=55></TEXTAREA> <P><INPUT TYPE="button" VALUE="Populate the textarea object" onClick="populate(document.form1.testLines)"> </TEXTAREA> </FORM>

    See also

  • appName, appCodeName, userAgent properties

    asin method

    Returns the arc sine (in radians) of a number.

    Syntax

    Math.asin(number)

    number is a numeric expression between -1 and 1, or a property of an existing object.

    Method of

    Math

    Description

    The asin method returns a numeric value between -pi/2 and pi/2 radians. If the value of number is outside the suggested range, the return value is always 0.

    Examples

    // Displays the value 1.570796326794897 (pi/2)
    document.write("The arc sine of 1 is " + Math.asin(1))
    
    // Displays the value -1.570796326794897 (-pi/2)
    document.write("<P>The arc sine of -1 is " + Math.asin(-1))
    
    // Displays the value 0 because the argument is out of range
    document.write("<P>The arc sine of 2 is " + Math.asin(2))
    

    See also

  • acos, atan, cos, sin, tan methods

    atan method

    Returns the arc tangent (in radians) of a number.

    Syntax

    Math.atan(number)

    number is either a numeric expression or a property of an existing object, representing the tangent of an angle.

    Method of

    Math

    Description

    The atan method returns a numeric value between -pi/2 and pi/2 radians.

    Examples

    // Displays the value 0.7853981633974483
    document.write("The arc tangent of 1 is " + Math.atan(1))
    
    // Displays the value -0.7853981633974483
    document.write("<P>The arc tangent of -1 is " + Math.atan(-1))
    
    // Displays the value 0.4636476090008061
    document.write("<P>The arc tangent of .5 is " + Math.atan(.5))
    

    See also

  • acos, asin, cos, sin, tan methods

    back method

    Loads the previous URL in the history list.

    Syntax

    history.back()

    Method of

    history

    Description

    This method performs the same action as a user choosing the Back button in the Navigator. The back method is the same as history.go(-1).

    Examples

    The following custom buttons perform the same operations as the Navigator Back and Forward buttons:
    <P><INPUT TYPE="button" VALUE="< Back"
       onClick="history.back()">
    <P><INPUT TYPE="button" VALUE="> Forward"
       onClick="history.forward()">
    

    See also

  • forward, go methods

    bgColor property

    A string specifying the color of the document background.

    Syntax

    document.bgColor

    Property of

    document

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

    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

    big method

    Causes a string to be displayed in a big font as if it were in a <BIG> tag.

    Syntax

    stringName.big()

    stringName is any string or a property of an existing object.

    Method of

    string

    Description

    Use the big method with the write or writeln methods to format and display a string in a document.

    Examples

    The following example uses string methods to change the size of a string:
    var worldString="Hello, world"
    
    document.write(worldString.small())
    document.write("<P>" + worldString.big())
    document.write("<P>" + worldString.fontsize(7))
    

    The previous example produces the same output as the following HTML:

    <SMALL>Hello, world</SMALL> <P><BIG>Hello, world</BIG> <P><FONTSIZE=7>Hello, world</FONTSIZE>

    See also

  • fontsize, small methods

    blink method

    Causes a string to blink as if it were in a <BLINK> tag.

    Syntax

    stringName.blink()

    stringName is any string or a property of an existing object.

    Method of

    string

    Description

    Use the blink method with the write or writeln methods to format and display a string in a document.

    Examples

    The following example uses string methods to change the formatting of a string:
    var worldString="Hello, world"
    
    document.write(worldString.blink())
    document.write("<P>" + worldString.bold())
    document.write("<P>" + worldString.italics())
    document.write("<P>" + worldString.strike())
    

    The previous example produces the same output as the following HTML:

    <BLINK>Hello, world</BLINK> <P><B>Hello, world</B> <P><I>Hello, world</I> <P><STRIKE>Hello, world</STRIKE>

    See also

  • bold, italics, strike methods

    blur method

    Removes focus from the specified object.

    Syntax

    1. passwordName.blur()
    2. selectName.blur()
    3. textName.blur()
    4. textareaName.blur()
    

    passwordName is either the value of the NAME attribute of a password 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.
    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.

    Method of

    password, select, text, textarea

    Description

    Use the blur method to remove focus from a specific form element.

    Examples

    The following example removes focus from the password element userPass:

    userPass.blur()
    
    This example assumes that the password is defined as:
    <INPUT TYPE="password" NAME="userPass">

    See also

  • focus, select methods

    bold method

    Causes a string to be displayed as bold as if it were in a <B> tag.

    Syntax

    stringName.bold()

    stringName is any string or a property of an existing object.

    Method of

    string

    Description

    Use the bold method with the write or writeln methods to format and display a string in a document.

    Examples

    The following example uses string methods to change the formatting of a string:
    var worldString="Hello, world"
    
    document.write(worldString.blink())
    document.write("<P>" + worldString.bold())
    document.write("<P>" + worldString.italics())
    document.write("<P>" + worldString.strike())
    

    The previous example produces the same output as the following HTML:

    <BLINK>Hello, world</BLINK>
    <P><B>Hello, world</B>
    <P><I>Hello, world</I>
    <P><STRIKE>Hello, world</STRIKE>
    

    See also

  • blink, italics, strike methods

    button object

    A pushbutton on an HTML form.

    Syntax

    To define a button:

    <INPUT
       TYPE="button"
       NAME="buttonName"
       VALUE="buttonText"
       [onClick="handlerText"]>
    
    NAME="buttonName" specifies the name of the button object. You can access this value using the name property.
    VALUE="buttonText" specifies the label to display on the button face. You can access this value using the value property.

    To use a button object's properties and methods:

    1. buttonName.propertyName
    2. buttonName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    buttonName is the value of the NAME attribute of a button object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a button object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Property of

  • form

    Description

    A button object on a form looks as follows:

    A button object is a form element and must be defined within a <FORM> tag.

    The button object is a custom button that you can use to perform an action you define. The button executes the script specified by its onClick event handler.

    Properties

  • name reflects the NAME attribute
  • value reflects the VALUE attribute

    Methods

  • click

    Event handlers

  • onClick

    Examples

    The following example creates a button named calcButton. The text "Calculate" is displayed on the face of the button. When the button is clicked, the function calcFunction() is called.

    <INPUT TYPE="button" VALUE="Calculate" NAME="calcButton" onClick="calcFunction(this.form)">

    See also

  • form, reset, and submit objects

    ceil method

    Returns the least integer greater than or equal to a number.

    Syntax

    Math.ceil(number)

    number is any numeric expression or a property of an existing object.

    Method of

    Math

    Examples

    //Displays the value 46
    document.write("The ceil of 45.95 is " + Math.ceil(45.95))
    
    //Displays the value -45
    document.write("<P>The ceil of -45.95 is " + Math.ceil(-45.95))
    

    See also

  • floor method

    charAt method

    Returns the character at the specified index.

    Syntax

    stringName.charAt(index)

    stringName is any string or a property of an existing object.
    index is any integer from 0 to stringName.length - 1, or a property of an existing object.

    Method of

    string

    Description

    Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character is stringName.length - 1. If the index you supply is out of range, JavaScript returns an empty string.

    Examples

    The following example displays characters at different locations in the string "Brave new world".
    var anyString="Brave new world"
    
    document.write("The character at index 0 is " + anyString.charAt(0))
    document.write("The character at index 1 is " + anyString.charAt(1))
    document.write("The character at index 2 is " + anyString.charAt(2))
    document.write("The character at index 3 is " + anyString.charAt(3))
    document.write("The character at index 4 is " + anyString.charAt(4))
    

    See also

  • indexOf, lastIndexOf methods

    checkbox object

    A checkbox on an HTML form. A checkbox is a toggle switch that lets the user set a value on or off.

    Syntax

    To define a checkbox, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT
       TYPE="checkbox"
       NAME="checkboxName"
       VALUE="checkboxValue"
       [CHECKED]
       [onClick="handlerText"]>
       textToDisplay
    
    NAME="checkboxName" specifies the name of the checkbox object. You can access this value using the name property.
    VALUE="checkboxValue" specifies a value that is returned to the server when the checkbox is selected and the form is submitted. This defaults to "on". You can access this value using the value property.
    CHECKED specifies that the checkbox is displayed as checked. You can access this value using the defaultChecked property.
    textToDisplay specifies the label to display beside the checkbox.

    To use a checkbox object's properties and methods:

    1. checkboxName.propertyName
    2. checkboxName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    checkboxName is the value of the NAME attribute of a checkbox object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a checkbox object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Property of

  • form

    Description

    A checkbox object on a form looks as follows:

    Overnight delivery

    A checkbox object is a form element and must be defined within a <FORM> tag.

    Use the checked property to specify whether the checkbox is currently checked. Use the defaultChecked property to specify whether the checkbox is checked when the form is loaded.

    Properties

  • checked lets you programatically check a checkbox
  • defaultChecked reflects the CHECKED attribute
  • name reflects the NAME attribute
  • value reflects the VALUE attribute

    Methods

  • click

    Event handlers

  • onClick

    Examples

    Example 1. The following example displays a group of four checkboxes that all appear checked by default.

    <B>Specify your music preferences (check all that apply):</B> <BR><INPUT TYPE="checkbox" NAME="musicpref_rnb" CHECKED> R&B <BR><INPUT TYPE="checkbox" NAME="musicpref_jazz" CHECKED> Jazz <BR><INPUT TYPE="checkbox" NAME="musicpref_blues" CHECKED> Blues <BR><INPUT TYPE="checkbox" NAME="musicpref_newage" CHECKED> New Age

    Example 2. The following example contains a form with three text boxes and one checkbox. The checkbox lets the user choose whether the text fields are converted to upper case. Each text field has an onChange event handler that converts the field value to upper case if the checkbox is checked. The checkbox has an onClick event handler that converts all fields to upper case when the user checks the checkbox.

    <HTML> <HEAD> <TITLE>Checkbox object example</TITLE> </HEAD> <SCRIPT> function convertField(field) { if (document.form1.convertUpper.checked) { field.value = field.value.toUpperCase()} } function convertAllFields() { document.form1.lastName.value = document.form1.lastName.value.toUpperCase() document.form1.firstName.value = document.form1.firstName.value.toUpperCase() document.form1.cityName.value = document.form1.cityName.value.toUpperCase() } </SCRIPT> <BODY> <FORM NAME="form1"> <B>Last name:</B> <INPUT TYPE="text" NAME="lastName" SIZE=20 onChange="convertField(this)"> <BR><B>First name:</B> <INPUT TYPE="text" NAME="firstName" SIZE=20 onChange="convertField(this)"> <BR><B>City:</B> <INPUT TYPE="text" NAME="cityName" SIZE=20 onChange="convertField(this)"> <P><INPUT TYPE="checkBox" NAME="convertUpper" onClick="if (this.checked) {convertAllFields()}" > Convert fields to upper case </FORM> </BODY> </HTML>

    See also

  • form and radio objects

    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.

    Property of

    checkbox, radio

    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.

    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 checkedButton = ""
       for (var i in document.musicForm.musicType) {
          if (document.musicForm.musicType[i].checked=="1") {
             checkedButton=document.musicForm.musicType[i].value
          }
       }
    }
    

    See also

  • defaultChecked property

    clear method

    Clears the document in a window.

    Syntax

    document.clear()

    Method of

    document

    Description

    The clear method empties the content of a window, regardless of how the content of the window has been painted.

    Examples

    When the following function is called, the clear method empties the contents of the msgWindow window:

    function windowCleaner() {
       msgWindow.document.clear()
       msgWindow.document.close()
    }
    

    See also

  • close, open, write, writeln methods

    clearTimeout method

    Cancels a timeout that was set with the setTimeout method.

    Syntax

    clearTimeout(timeoutID)

    timeoutID is a timeout setting that was returned by a previous call to the setTimeout method.

    Method of

    frame, window

    Description

    See the description for the setTimeout method.

    Examples

    See the examples for the setTimeout method.

    See also

  • setTimeout method

    click method

    Simulates a mouse click on the calling form element.

    Syntax

    1. buttonName.click()
    2. radioName[index].click()
    
    3. checkboxName.click()

    buttonName is either the value of the NAME attribute of a button, reset, or submit object or an element in the elements array.
    radioName is the value of the NAME attribute of a radio object or an element in the elements array.
    index is an integer representing a radio button in a radio object.
    checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array.

    Method of

    button, checkbox, radio, reset, submit

    Description

    The effect of the click method varies according to the calling element:

  • For button, reset, and submit, performs the same action as clicking the button.
  • For a radio, selects a radio button.
  • For a checkbox, checks the checkbox and sets its value to on.

    Examples

    The following example toggles the selection status of the first radio button in the musicType radio object on the musicForm form:

    document.musicForm.musicType[0].click()

    The following example toggles the selection status of the newAge checkbox on the musicForm form:

    document.musicForm.newAge.click()

    close method (document object)

    Closes an output stream and forces data sent to layout to display.

    Syntax

    document.close()

    Method of

    document

    Description

    The close method closes a stream opened with the document.open() method. If the stream was opened to layout, the close method forces the content of the stream to display. Font style tags, such as <BIG> and <CENTER>, automatically flush a layout stream.

    The close method also stops the "meteor shower" in the Netscape icon and displays "Document: Done" in the status bar.

    Examples

    The following function calls document.close() to close a stream that was opened with document.open(). The document.close() method forces the content of the stream to display in the window.
    function windowWriter1() {
       var myString = "Hello, world!"
       msgWindow.document.open()
       msgWindow.document.write(myString + "<P>")
       msgWindow.document.close()
    }
    

    See also

  • clear, open, write, writeln methods

    close method (window object)

    Closes the specified window.

    Syntax

    windowReference.close()

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

    Method of

    window

    Description

    The close method closes the specified window. If you call close without specifying a windowReference, JavaScript closes the current window.

    In event handlers, you must specify window.close() instead of simply using close(). Due to the scoping of static objects in JavaScript, a call to close() without specifying an object name is equivalent to document.close().

    Examples

    Any of the following examples close the current window:

    window.close()
    self.close()
    close()

    The following example closes the messageWin window:

    messageWin.close()

    This example assumes that the window was opened in a manner similar to the following:

    messageWin=window.open("")

    See also

  • open method

    confirm method

    Displays a Confirm dialog box with the specified message and OK and Cancel buttons.

    Syntax

    confirm("message")

    message is any string or a property of an existing object.

    Method of

    window

    Description

    Use the confirm method to ask the user to make a decision that requires either an OK or a Cancel. The message argument specifies a message that prompts the user for the decision. The confirm method returns true if the user chooses OK and false if the user chooses Cancel.

    Although confirm is a method of the window object, you do not need to specify a windowReference when you call it. For example, windowReference.confirm() is unnecessary.

    Examples

    This example uses the confirm method in the confirmCleanUp() function to confirm that the user of an application really wants to quit. If the user chooses OK, the custom cleanUp() function closes the application.

    function confirmCleanUp() {
       if (confirm("Are you sure you want to quit this application?")) {
          cleanUp()
       }
    }
    You can call the confirmCleanUp() function in the onClick event handler of a form's pushbutton, as shown in the following example:
    <INPUT TYPE="button" VALUE="Quit" onClick="confirmCleanUp()">

    See also

  • alert, prompt methods

    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

    Property of

    document

    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.

    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. The format of the date must be

    Wdy, DD-Mon-YY HH:MM:SS GMT
    
    where Wdy is the full name of the day of the week, DD is an integer representation of the day of the month, Mon is the month, YY is the last two digits of the year, and HH, MM, and SS are two-digit representations of hours, minutes, and seconds, respectively.

    This is the same date format as returned by Date.toGMTString, except:

    For example, a valid cookie expiration date is:
    expires=Wednesday, 09-Nov-99 23:12:40 GMT

    function RecordReminder(time, expression) {
       // Record a cookie of the form "@=" to map
       // from  in milliseconds since the epoch,
       //  returned by Date.getTime(), onto an encoded expression,
       //  (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=" + cookieDate(time + 24*60*60*1000)
       // cookieDate is a function that formats the date according to the cookie spec
    }
    

    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

    cos method

    Returns the cosine of a number.

    Syntax

    Math.cos(number)

    number is a numeric expression representing the size of an angle in radians, or a property of an existing object.

    Method of

    Math

    Description

    The cos method returns a numeric value between -1 and 1, which represents the cosine of the angle.

    Examples

    
    //Displays the value 6.123031769111886e-017
    document.write("The cosine of PI/2 radians is " + Math.cos(Math.PI/2))
    
    //Displays the value -1
    document.write("<P>The cosine of PI radians is " + Math.cos(Math.PI))
    
    //Displays the value 1
    document.write("<P>The cosine of 0 radians is " + Math.cos(0))
    

    See also

  • acos, asin, atan, sin, tan methods