Javascript method to get the form name (name)

  • 2020-05-26 07:47:18
  • OfStack

This example shows how Javascript gets the form name (name). Share with you for your reference. The details are as follows:

The following code gets the form name through the name property of the form


<!DOCTYPE html>
<html>
<body>
<form id="frm1" name="form1">
First name: <input type="text" name="fname" value="Donald"><br>
Last name: <input type="text" name="lname" value="Duck"><br>
</form>
<p>The name of the form is:
<script>
document.write(document.getElementById("frm1").name);
</script>
</p>
</body>
</html>

The results of the above code are as follows:


The name of the form is:form1

I hope this article is helpful to you in javascript programming.


Related articles: