The forms
collection returns an array
of all the forms in the current document.
document.forms[].property
forms Collection |
Yes | Yes | Yes | Yes | Yes |
The following code shows how to return the number of forms in the document.
<!DOCTYPE html>
<html>
<body>
<!--from w w w . j a v a 2 s.c o m-->
<form name="Form1"></form>
<form name="Form2"></form>
<form></form>
<p>Number of forms:
<script>
document.write(document.forms.length);
</script></p>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the name of the first form in the document.
<!DOCTYPE html>
<html>
<body>
<form name="Form1"></form>
<form name="Form2"></form>
<form></form>
<!-- w ww. ja va 2 s. c om-->
<p>Name of first form:
<script>
document.write(document.forms[0].name);
</script></p>
</body>
</html>
The code above is rendered as follows: