JavaScript method to get the number of forms (form) in a page
- 2020-05-26 07:42:52
- OfStack
This example shows how JavaScript gets the number of forms (form) on a page. Share with you for your reference. The details are as follows:
The JS code below gets the number of forms (form) in the web page through the document.forms array
<!DOCTYPE html>
<html>
<body>
<h1>sharejs.com</h1>
<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 results are as follows:
Number of forms: 3
I hope this article is helpful for you to design javascript program.