English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM forms attribute

HTML DOM Document Object

formsA read-only attribute returns the embedded<FORM>List of elements.

The elements in the list are sorted in the order they appear in the source code.

If the document does not have a form, the returned list is empty and the length is zero.

Syntax:

document.forms
var x = document.forms.length;
Test and see‹/›

Browser compatibility

All browsers fully support the forms attribute:

Attribute
formsIsIsIsIsIs

Nature

AttributeDescription
lengthReturns the list in<form>Number of elements

Method

MethodDescription
[index]Returns the specific node at the given index, starting from zero, in the list. If the index number is out of range, it returns null.
item(index)Returns the specific node at the given index, starting from zero, in the list. If the index number is out of range, it returns null.
namedItem(id)Returns the specific node that matches the ID name specified with name. If the ID does not exist, it returns null.

Technical Details

Return Value:List all document formsHTMLCollectionObject. Each item in the collection is an HTMLFormElement, representing a single <form> element.
DOM Version:DOM Level1

More Examples

Get the ID of the <form> element in the document:

alert(document.forms[0].id);
Test and see‹/›

Use id="alphaForm" to get the HTML content of the form element:

var x = document.forms.namedItem(&39;alphaForm').innerHTML;
Test and see‹/›

HTML DOM Document Object