HTML DOM formsCollection

Document 对象参考手册Document Object

Definition and Usage

The forms collection returns an array collection of all forms on the current page.

Syntax

document.forms[].property


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the forms collection.


Examples

Example 1

Returns the number of forms in the document:

<html>
<body>

<form name="Form1"></form>
<form name="Form2"></form>
<form></form>

<p>Number of forms:
<script>
document.write(document.forms.length);
</script></p>

</body>
</html>

Output of the above example:

Number of forms: 3


Try it yourself »

Example 2

Returns the name of the first form in the document:

<html>
<body>

<form name="Form1"></form>
<form name="Form2"></form>
<form></form>

<p>Name of the first form:
<script>
document.write(document.forms[0].name);
</script></p>

</body>
</html>

Output of the above example:

Name of the first form: Form1

Try it yourself »


Document 对象参考手册Document Object Other Extensions