Reset
A reset button on an HTML form. A reset button resets all elements in a form to their defaults.Created by
The HTMLINPUT tag, with "reset" as the value of the TYPE attribute. For a given form, the JavaScript runtime engine creates an appropriate Reset object and puts it in the elements array of the corresponding Form object. You access a Reset object by indexing this array. You can index the array either by number or, if supplied, by using the value of the NAME attribute.
Event handlers
Description
AReset object on a form looks as follows:
Reset object is a form element and must be defined within a FORM tag.
The reset button's onClick event handler cannot prevent a form from being reset; once the button is clicked, the reset cannot be canceled.
Property Summary
| Property |
Description
|
|
|
| |
|---|
Method Summary
| Method |
Description
|
|
|
| |
|---|
watch and unwatch methods from Object.
Examples
Example 1. The following example displays aText object with the default value "CA" and a reset button with the text "Clear Form" displayed on its face. If the user types a state abbreviation in the Text object and then clicks the Clear Form button, the original value of "CA" is restored.
<B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2">Example 2. The following example displays two
<P><INPUT TYPE="reset" VALUE="Clear Form">
Text objects, a Select object, and three radio buttons; all of these objects have default values. The form also has a reset button with the text "Defaults" on its face. If the user changes the value of any of the objects and then clicks the Defaults button, the original values are restored.
<HTML>
<HEAD>
<TITLE>Reset object example</TITLE>
</HEAD>
<BODY>
<FORM NAME="form1">
<BR><B>City: </B><INPUT TYPE="text" NAME="city" VALUE="Santa Cruz" SIZE="20">
<B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2">
<P><SELECT NAME="colorChoice">
<OPTION SELECTED> Blue
<OPTION> Yellow
<OPTION> Green
<OPTION> Red
</SELECT>
<P><INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b"
CHECKED> Soul and R&B
<BR><INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz">
Jazz
<BR><INPUT TYPE="radio" NAME="musicChoice" VALUE="classical">
Classical
<P><INPUT TYPE="reset" VALUE="Defaults" NAME="reset1">
</FORM>
</BODY>
</HTML>
See also
Button, Form, onReset, Form.reset, Submit
blur
Removes focus from the reset button.Syntax
blur()
Parameters
NoneExamples
The following example removes focus from the reset buttonuserReset:
userReset.blur()This example assumes that the button is defined as
<INPUT TYPE="reset" NAME="userReset">
See also
Reset.focus
click
Simulates a mouse-click on the reset button, but does not trigger an object'sonClick event handler.Syntax
click()
Parameters
Nonefocus
Navigates to the reset button and gives it focus.Syntax
focus()
Parameters
NoneSee also
Reset.blur
form
An object reference specifying the form containing the reset button.Description
Each form element has aform 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.
See also
Form
handleEvent
Invokes the handler for the specified event.Syntax
handleEvent(event)
Parameters
event | The name of an event for which the specified object has an event handler. |
name
A string specifying the name of the reset button.Security
JavaScript 1.1. This property is tainted by default. For information on data tainting, see the Client-Side JavaScript Guide.Description
The value of thename property initially reflects the value of the NAME attribute. Changing the name property overrides this setting.
Do not confuse the name property with the label displayed on the reset button. The value property specifies the label for this button. The name property is not displayed on the screen; it is used to refer programmatically to the button.
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 in source order starting at 0. For example, if two Text elements and a Reset 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. 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.
Examples
In the following example, thevalueGetter 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://home.netscape.com")
function valueGetter() {
var msgWindow=window.open("")
for (var i = 0; i < newWindow.document.valueTest.elements.length; i++) {
msgWindow.document.write(newWindow.document.valueTest.elements[i].name + "<BR>")
}
}
See also
Reset.value
type
For allReset objects, the value of the type property is "reset". This property specifies the form element's type.Examples
The following example writes the value of thetype property for every element on a form.
for (var i = 0; i < document.form1.elements.length; i++) {
document.writeln("<BR>type is " + document.form1.elements[i].type)
}
value
A string that reflects the reset button'sVALUE attribute.Security
JavaScript 1.1. This property is tainted by default. For information on data tainting, see the Client-Side JavaScript Guide.Description
This string is displayed on the face of the button. When aVALUE attribute is not specified in HTML, the value property is the string "Reset".
Do not confuse the value property with the name property. The name property is not displayed on the screen; it is used to refer programmatically to the button.
Examples
The following function evaluates thevalue property of a group of buttons and displays it in the msgWindow window:
function valueGetter() {This example displays the following values:
var 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()
}
Query SubmitThe previous example assumes the buttons have been defined as follows:
Reset
Help
<INPUT TYPE="submit" NAME="submitButton">
<INPUT TYPE="reset" NAME="resetButton">
<INPUT TYPE="button" NAME="helpButton" VALUE="Help">
See also
Reset.name
Table of Contents | Previous | Next | Index
Last Updated: 05/28/99 12:00:19
