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 |
A String, representing the name of the form
The following code shows how to return the name of a form:
<!DOCTYPE html> <html> <body> <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> <script> function myFunction() { var v = document.getElementById("myForm").name; document.getElementById("demo").innerHTML = v; } </script> </body> </html>