How to find the name of the first form in a document with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To get the name of the first form in a document, use the forms property with You can try to run the following code to display the name −


Live Demo

<!DOCTYPE html>
      <form name ="formOne">
         Name: <input type="text" name="my_name" value="Amit">
         Subject: <input type="text" name="my_subject" value="Java">
         <input type="submit" value="Submit">
      <form name ="formTwo">
         var val = document.forms.length;
         document.write("<br>Number of forms in the document: "+val);
         document.write("<br>Name of the first form: "+document.forms[0].name)
Published on 26-Feb-2018 07:47:57