How to get the number of forms in a document with JavaScript?

JavascriptWeb DevelopmentFront End Technology

To get the number of forms in a document, use the form property with length property in JavaScript.

Example

You can try to run the following code to get the number of forms in a document −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <form>
         Name: <input type="text" name="my_name" value="Amit">
         Subject: <input type="text" name="my_subject" value="Java">
         <input type="submit" value="Submit">
      </form>
      <script>
         var val = document.forms.length;
         document.write("<br>Number of forms in the document: "+val);
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 12:12:33
Advertisements