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, enabled click, focus onClick, onFocus
check box form, name, value, checked, defaultChecked, enabled click, focus onClick, onFocus
radio form, name, value, checked, enabled click, focus onClick, onFocus
combo form, name, value, enabled, listCount, list, multiSelect, listIndex click, focus, removeItem, addItem, clear onClick, onFocus
password form, name, value, defaultValue, enabled focus, blur, select onFocus, onBlur
text, text area form, name, value, defaultValue, enabled 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, removeItem, addItem, clear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


Properties


form Property

Description

Gets the form object containing the element.

Syntax

element.form

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

Return Value

An object expression that evaluates to the form containing the element

Applies To

All elements

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, 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, removeItem, addItemclear

Events

onFocus, onBlur, onChange, onSelect

Properties

form, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, 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, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, 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, text area

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


checked Property

Description

Gets or sets the checked state of the check box or the radio button.

Syntax

element.checked [=bool]

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

Return Value

Returns TRUE if the check box or radio button is checked; FALSE if not.

Applies To

check box, radio button

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


defaultChecked Property

Description

Gets or sets the default checked property of the check box.

Syntax

element.defaultChecked [=bool]

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

Return Value

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

Applies To

check box

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


enabled Property

Description

Gets or sets whether the control is enabled.

Syntax

element.enabled [=bool]

PartDescription
element An object expression that evaluates to an intrinsic control.
bool Optional. Enables or disables the control.

Return Value

Returns TRUE if the control is enabled; FALSE if not.

Applies To

All elements

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, listCount, multiSelect, listIndex, length, options, selectedIndex


listCount Property

Description

Gets the count of elements in the list.

Syntax

element.listCount

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

Return Value

Returns the number of elements in the combo box.

Applies To

combo

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, multiSelect, listIndex, length, options, selectedIndex


multiSelect Property

Description

Gets or sets whether the combo is multiselect or not.

Syntax

element.multiSelect [=bool]

PartDescription
element An object expression that evaluates to an intrinsic control.
bool Optional. Use TRUE to set the combo to multiselect; FALSE to set to single-select.

Return Value

Returns TRUE if the combo is multiselect; FALSE if not.

Applies To

combo

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, listIndex, length, options, selectedIndex


listIndex Property

Description

Gets or sets the list index.

Syntax

element.listIndex [=integer]

PartDescription
element An object expression that evaluates to an intrinsic control.
Integer Optional. The list index to select. Note that this must be between 0 and ListCount - 1.

Return Value

Returns the index of the currently selected element. If more than one is selected, it returns the first.

Remarks

listIndex is the index of the selected element in the combo. Applies to the combo element.

Applies To

combo

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, 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, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, 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 string specifying the <options> tag for a select element.

Remarks

The options array has the following properties:

Applies To

select

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, selectedIndex


selectedIndex Property

Description

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

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, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, 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, check box, radio, combo

Methods

focus, blur, select, removeItem, addItem, clear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, 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

All elements

Methods

click blur, select, removeItem, addItem, clear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, 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, text area

Methods

click, focus, select, removeItem, addItem, clear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, 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, text area

Methods

click, focus, blur, removeItem, addItem, clear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


removeItem Method

Description

Removes the item at index from the element.

Syntax

element.removeItem index

PartDescription
element An object expression that evaluates to an intrinsic control.
index The index of the item to remove. Note that this must be between 0 and ListCount - 1.

Applies To

combo

Methods

click, focus, blur, select, addItem, clear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


addItem Method

Description

Adds the item to the element before the item at index.

Syntax

element.addItem index

PartDescription
element An object expression that evaluates to an intrinsic control.
index The index of the item to add. Note that this must be between 0 and ListCount.

Applies To

combo

Methods

click, focus, blur, select, removeItem, clear

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


clear Method

Description

Clears the contents of the element.

Syntax

element.clear index

PartDescription
element An object expression that evaluates to an intrinsic control.
index The index of the item to clear.

Applies To

combo

Methods

click, focus, blur, select, removeItem, addItem

Events

onClick, onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


Events

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 elements, plus any elements 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 me">
         <script for="Button1" event="onClick" language="VBScript">
         alert "I've been pressed"
         document.Form1.Button1.value="OUCH"
         </script>
    </form>
    


onClick Event

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, check box, radio, combo

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onFocus, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


onFocus Event

Description

Fired when the element gets the focus.

Syntax

element.onFocus

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

Applies To

All elements

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onBlur, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


onBlur Event

Description

Fired when the element loses the focus.

Syntax

element.onBlur

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

Applies To

password, text, text area

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onChange, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


onChange Event

Description

Fired when the element has changed.

Syntax

element.onChange

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

Applies To

text, text area

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onSelect

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex


onSelect Event

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, text area

Methods

click, focus, blur, select, removeItem, addItemclear

Events

onClick, onFocus, onBlur, onChange

Properties

form, name, value, defaultValue, checked, defaultChecked, enabled, listCount, multiSelect, listIndex, length, options, selectedIndex

© 1996 Microsoft Corporation