Previous Up Index Next

Element Object


element Object

Description

An object that resides below the document in the scripting object model. Elements are intrinsic HTML controls or objects. Controls are placed on a document with the <INPUT> tag while objects are placed on a document with the <OBJECT> tag.

Elements are intrinsic HTML controls (placed on a page through the input tag <INPUT>) or objects that are insertable in HTML via the object tag <OBJECT>. These include ActiveX Controls. They can be referenced either by array or name, but this reference must follow the form identifier. Not all properties, methods, and events apply to all elements. Some properties apply to all elements; some only apply to specific elements. See the list below for details by element type, then see the specific method, event, or property documentation for details.
Element Properties Methods Events
button, reset, submit form, name, value click onClick
checkbox form, name, value, checked, defaultChecked click onClick
radio form, name, value, checked click, focus onClick
password form, name, value, defaultValue focus, blur, select
text, textarea form, name, value, defaultValue focus, blur, select onFocus, onBlur, onChange, onSelect
select name, length, options, selectedIndex focus, blur onFocus, onBlur, onChange
hidden name, value

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


Properties


form Property

Description

Gets the form object containing the element.

Syntax

element.form

PartDescription
element An object expression that evaluates to the form containing the element

Return Value

Returns an object expression that evaluates to a form object.

Applies To

All elements except select and hidden.

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


name Property

Description

Gets or sets the name of the element.

Syntax

element.name [=string]

PartDescription
element An object expression that evaluates to an intrinsic control.
string Optional. A string containing the new element name.

Return Value

Returns a string containing the name of the element.

Applies To

All elements

Methods

click, focus, blur, select

Events

onFocus, onBlur, onChange, onSelect

Properties

form, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


value Property

Description

Gets or sets the value of the element.

Syntax

element.value [=string]

PartDescription
element An object expression that evaluates to an intrinsic control.
string Optional. A string containing the new element value.

Return Value

Returns a string containing the value of the element.

Applies To

All elements

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, defaultValue, checked, defaultChecked, length, options, selectedIndex


defaultValue Property

Description

Gets or sets the default value of the element.

Syntax

element.defaultValue [=string]

PartDescription
element An object expression that evaluates to an intrinsic control.
string Optional. A string containing the new default value.

Return Value

Returns a string containing the default value of the element.

Applies To

password, text, textarea

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, checked, defaultChecked, length, options, selectedIndex


checked Property

Description

Gets or sets the checked state of the checkbox.

Syntax

element.checked [=bool]

PartDescription
element An object expression that evaluates to an intrinsic control.
string Optional. Sets the checked state of the checkbox or the radio button.

Return Value

Returns 1 if the checkbox or radio button is checked; 0 if not.

Applies To

checkbox, radio button

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, defaultChecked, length, options, selectedIndex


defaultChecked Property

Description

Gets or sets the default checked property of the checkbox.

Syntax

element.defaultChecked [=bool]

PartDescription
element An object expression that evaluates to an intrinsic control.
string Optional. Sets the default state of the checkbox.

Return Value

Returns TRUE if the checkbox is checked by default; FALSE if not.

Applies To

checkbox

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, length, options, selectedIndex


length Property

Description

Gets the number of options in a select element.

Syntax

element.length

PartDescription
element An object expression that evaluates to a select element.

Return Value

Returns an integer specifying the number of options in a select element.

Applies To

select

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, options, selectedIndex


options Property

Description

Gets the <options> tags for a select element.

Syntax

element.options

PartDescription
element An object expression that evaluates to a select element.

Return Value

Returns an object with the <options> for a select element.

Remarks

The options array has the following properties:
defaultSelected Identifies the currently selected attribute.
index Specifies the index of an option.
length Specifies the number of options in the selected object.
name Specifies the name attribute of the selected object.
selected Used to programmatically select an option.
selectedIndex Specifies the index of the selected option.
text Specifies the text to be displayed (this text follows the <option> tag).
value Specifies the value attribute.

Applies To

select

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, selectedIndex


selectedIndex Property

Description

Gets the index for the selected option (or the first option selected when there are multiple selected options).

Syntax

element.selectedIndex

PartDescription
element An object expression that evaluates to a select element.

Return Value

Returns an integer specifying the index for the selected option in a select element.

Applies To

select

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options


Methods


click Method

Description

Clicks the element.

Syntax

element.click

PartDescription
element An object expression that evaluates to an intrinsic control.

Applies To

button, reset, submit, checkbox, radio

Methods

focus, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


focus Method

Description

Sets the focus to the element.

Syntax

element.focus

PartDescription
element An object expression that evaluates to an intrinsic control.

Applies To

password, text, textarea, select

Methods

click, blur, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


blur Method

Description

Clears the focus from the element.

Syntax

element.blur

PartDescription
element An object expression that evaluates to an intrinsic control.

Applies To

password, text, textarea, select

Methods

click, focus, select

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


select Method

Description

Selects the contents of the element.

Syntax

element.select

PartDescription
element An object expression that evaluates to an intrinsic control.

Applies To

password, text, textarea

Methods

click, focus, blur

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


Event Handlers

There are two ways to script events from objects:

  1. Using the onEvent="subroutine" syntax. This method can be used for any HTML intrinsic elements, such as forms, buttons, or links. This method does not work for items inserted using the OBJECT tag. The following example uses this syntax in Button1 to handle onClick:
    
    <form name="Form1">
         <input type="button" name="Button1" value="Press me" onClick="pressed">
    </form> 
    
    <script language="VBScript">
         sub pressed
         alert "I've been pressed"
         document.Form1.Button1.value="OUCH"
         end sub    
    </script>
    
  2. Using the FOR="object" EVENT="eventname" syntax. This method can be used for any named element and any element inserted using the OBJECT tag. The following example is the same as the first but with a different syntax:
    
    <form name="Form1">
         input type="button" name="Button1" value="Press">
         <script for="Button1" event="onClick" language="VBScript">
         alert "Button pressed"
         document.Form1.Button1.value="Pressed"
         </script>
    </form>
    


onClick Event Handler

Description

Fired when the element is clicked.

Syntax

element.onClick

ValueDescription
element An object expression that evaluates to an intrinsic control.

Applies To

button, reset, submit, checkbox, radio

Methods

click, focus, blur, select

Events

onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


onFocus Event Handler

Description

Fired when the element gets the focus.

Syntax

element.onFocus

ValueDescription
element An object expression that evaluates to an intrinsic control.

Applies To

select, text, textarea

Methods

click, focus, blur, select

Events

onClick, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


onBlur Event Handler

Description

Fired when the element loses the focus.

Syntax

element.onBlur

ValueDescription
element An object expression that evaluates to an intrinsic control.

Applies To

select, text, textarea

Methods

click, focus, blur, select

Events

onClick, onFocus, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


onChange Event Handler

Description

Fired when the element has changed.

Syntax

element.onChange

ValueDescription
element An object expression that evaluates to an intrinsic control.

Applies To

select, text, textarea

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex


onSelect Event Handler

Description

Fired when the contents of the element are selected.

Syntax

element.onSelect

ValueDescription
element An object expression that evaluates to an intrinsic control.

Applies To

text, textarea

Methods

click, focus, blur, select

Events

onClick, onFocus, onBlur, onChange

Properties

form, name, value, defaultValue, checked, defaultChecked, length, options, selectedIndex

Previous Up Index Next

© 1996 Microsoft Corporation