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.
Specifies the form containing the Button object.
Reflects the NAME attribute.
Reflects the TYPE> attribute.
Reflects the VALUE attribute.
Removes focus from the button.
Simulates a mouse-click on the button.
Gives focus to the button.
Invokes the handler for the specified event.
In addition, this object inherits the watch and unwatch methods from Object
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.
An object reference specifying the form containing the button.
Each form element has a form property that is a reference to the element's parent form. This property is especially useful in event handlers, where you might need to refer to another element on the current form.
Example 1. In the following example, the form myForm contains a Text object and a button. When the user clicks the button, the value of the Text object is set to the form's name. The button's onClick event handler uses this.form to refer to the parent form, myForm.
<FORM NAME="myForm"> Form name:<INPUT TYPE="text" NAME="text1" VALUE="Beluga"> <P> <INPUT NAME="button1" TYPE="button" VALUE="Show Form Name" onClick="this.form.text1.value=this.form.name"> </FORM>
elements and a Button element on the same form have their NAME attribute set to "myField", an array with the elements myField, myField, and myField is created. You need to be aware of this situation in your code and know whether myField refers to a single element or to an array of elements.
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: