Name
Form: a <form> in an HTML document — DOM Level 2 HTML: Node → Element → HTMLElement → Form
Properties
-
readonly HTMLCollection elements An array (HTMLCollection) of all elements in the form. See
Form.elements[].-
readonly long length The number of form elements in the form. This is the same value as
elements.length.
In addition to these properties, Form also defines the properties in the following table, which correspond directly to HTML attributes:
|
Property |
Attribute |
Description |
|
|
|
Character sets the server can accept |
|
|
|
URL of the form handler |
|
|
|
Encoding of the form |
|
|
|
HTTP method used for form submission |
|
|
|
Name of the form |
|
|
|
Frame or window name for form submission results |
Methods
-
reset( ) Resets all form elements to their default values.
-
submit( ) Submits the form to a web server.
Event Handlers
-
onreset Invoked just before the elements of the form are reset.
-
onsubmit Invoked just before the form is submitted. This event handler allows form entries to be validated before being submitted.
HTML Syntax
A Form object is created with a standard HTML <form> tag. The form contains input
elements created with <input>, <select>, <textarea>, and other tags:
<form
[ name="form_name" ] // Used to name the form in JavaScript
[ target="window_name" ] // The name of the window for responses
[ action="url" ] // The URL to which the ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access