Form name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form


The name property sets or gets the name attribute in a form.

The name attribute sets the name of a form.

Set the name property with the following Values

Value Description
name The name of the form

Return Value

A String, representing the name of the form

The following code shows how to return the name of a form:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<form id="myForm" name="form1" action="#">
  First name: <input type="text" name="fname" value="Donald"><br>
  Last name: <input type="text" name="lname" value="Duck"><br>
  <input type="submit" value="Submit">
</form>/*ww  w .  j a v a  2 s .c o m*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    var v = document.getElementById("myForm").name;
    document.getElementById("demo").innerHTML = v;


Related Tutorials