9.17. Submit and Reset Buttons

Submit and reset buttons provide control mechanisms for users to submit the data entered to a handler and reset the form to its default state, respectively. These buttons have similar formats:

<input type="submit" name="submit" id="submit" [value="text_for_button"] />

and

<input type="reset" name="reset" id="reset" [value="text_for_button"] />

The value attribute for both tags is optional; if this attribute is omitted, the buttons will display default text (usually "Submit" and "Reset," but the text is ultimately determined by the user agent).

The submit button, when clicked, causes the form to be submitted to the handler specified in the <form> tag's action attribute. You can also use the onclick event attribute to call a script to preprocess the form data prior to submission.

The reset button, when clicked, causes the form to be reloaded and its fields reset to their default values. You can also use the onclick event attribute to change the button's behavior, calling a script instead of reloading the form. However, the user will expect the reset button to ultimately reset the form; if you tie a script to the button using the onclick event, you should ensure that the script also resets the form.

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.