Javascript Form How to - Get form method value: GET or POST








Question

We would like to know how to get form method value: GET or POST.

Answer


<!--   w  ww  . j  a v a 2s .c o  m-->
<html>
    <body>
    <script language="JavaScript">
    function informMethod(){
        console.log("The form method is:" + document.form1.method);
    }
    </script>
    <form name="form1" method="get">
        First Name:<input type=text" name="first" size=15>
        Last Name:<input type=text" name="last" size=25>
        <br>
        City:<input type=text" name="city" size=20>
        State:<input type=text" name="state" size=2 maxlength=2>
        Zip:<input type=text" name="zip" size=5 maxlength=5>
        <br><br>
        Click the button to see what type of Method is used for submission.
        <input type="button" value="Click Here" onClick='informMethod()'>
    </form>
    </body>
</html>

The code above is rendered as follows: