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

String acceptCharset

acceptcharset

Character sets the server can accept

String action

action

URL of the form handler

String enctype

enctype

Encoding of the form

String method

method

HTTP method used for form submission

String name

name

Name of the form

String target

target

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 ...

Get JavaScript: The Definitive Guide, 5th Edition 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.