Javascript Form How to - Get form name value








Question

We would like to know how to get form name value.

Answer


<!--from  w  w w . j  a  v a  2s  . com-->
<html>
    <body>
    <script language="JavaScript">
    function showName(){
        console.log("Form Name is: " + document.form1.name);
    }
    </script>
    <form name ="form1" >
        Dummy input text box.
        <input type= "text" size="15">
        <br><br>
        Click on the button to get the name of the form
        <input type="button" value="click me" onclick='showName()'>
    </form>
    </body>
</html>

The code above is rendered as follows: