button (type=reset) element
If you don't know what an element is or how you must use it, I recommend you read the "HTML tags and attributes" tutorial that you can find in the HTML tutorials section.
Table of contents
Description
The button
element, having the "reset" value in its type
attribute, represents a button that, when pressed, resets all the fields in the form
it belongs to, to their initial values. The label of a button
is represented by the content of the element.
Examples
In this example we'll set up a form
with a number of fields of different types, each of which has an initial value. Additionally a reset button will be provided to check its functionality.
<form action="../../form-result.php">
<p>Nombre: <input type="text" value="Tu nombre"></p>
<p><input type="checkbox" checked> Viajes</p>
<p><input type="checkbox"> Deportes</p>
<p><button type="reset">Restaurar</button></p>
</form>
Now we'll see the special feature of the button
element, which lets it hold other non-interactive elements. This is one of the main differences it has with the intput
(type=reset) element.
<form action="../../form-result.php">
<p>Name: <input type="text" value="Your name"></p>
<p><button type="reset">Reseting <i>this</i> form is <b>super cool</b></button></p>
</form>
Attributes
Specific attributes
autofocus
A boolean value instructing the browser to set the focus to this control when the document has finished loading or when the dialog
where the control finds itself is shown. If the attribute has the value "autofocus" or the empty string (""), or if it's just present, the control should get the focus as soon as possible, after the page or dialog
has been loaded.
Example
<button type="reset" autofocus>Reset</button>
disabled
A boolean value indicating wether the control is disabled or not. If the attribute takes the value "disabled" or the empty string (""), or if it's just present, the control will be disabled.
Disabled controls are rendered greyed out (if visible), are blocked from user interaction and, more importantly, their values (if any) aren't sent when the form
is submitted.
Example
<form action="../../form-result.php">
<p>
City: <input type="text" name="city" value="Manhattan">
<button type="button" disabled>Reset form... if you can</button>
</p>
</form>
form
The value of the id
attribute of the form with which this control is associated to.
This attribute is new in HTML5 and helps defining the pertenence of controls in nested or distant forms.
Example
<form id="form1" action="../../form-result.php">
<p>Assistant: <input type="text" name="assistant"></p>
</form>
<button type="reset" form="form1">Reset form</button>
name
A name for the control. This name will be sent by the browser to the processing agent, paired with the content of the value
attribute. Both attributes together will conform a name-value pair that will be used to process the form data.
Currently, the value isindex
, formerly used in a special way by some browsers and included in the HTML standard, isn't permitted in this attribute.
The name-value pair of a button is submitted, with the other form data, only if the button has been used to submit the form.
Example
<button type="button" name="coolresetbutton" value="Hi!">Reset</button>
type
A value indicating the expected behavior of the button. There are four possible values (case-insensitive) that will decide the default action carried out by the button when it's pressed:
- button: there's no default action associated to the control. The behavior of this type of buttons is usually provided by a script.
- reset: the controls of the associated form are reset to their initial values.
- submit: the associated form is submitted. This is the deafult value.
- menu: the context menu associated to this button is deployed.
When this attribute isn't present, the button behaves as a "submit" button.
Example
<button type="reset">Reset the form</button>
value
A value for the control. This value will be sent by the browser to the processing agent, paired with the content of the name
attribute. Both attributes together will conform a name-value pair that will be used to process the form data.
The name-value pair of a button is submitted, with the other form data, only if the button has been used to submit the form.
Example
<button type="reset" name="coolresetbutton" value="Hi!">Reset</button>
Global attributes
For information about global attributes refer to this list of global attributes in HTML5.
Events
Global events
For information about global events refer to this list of global events in HTML5.