HTML | method Attribute

The HTML | method Attribute is used to specify the HTTP method used to send data while submitting the form. There are two kinds of HTTP Methods, which are GET and POST. The method attribute can be used with the <form> element.

Attribute Values:

  • GET: In the GET method, after the submission of the form, the form values will be visible in the address bar of the new browser tab. It has a limited size of about 3000 characters. It is only useful for non-secure data not for sensitive information.
  • POST: In the post method, after the submission of the form, the form values will not be visible in the address bar of the new browser tab as it was visible in the GET method. It appends form data inside the body of the HTTP request. It has no size limitation. This method does not support bookmark the result.

Syntax:



<form method="get|post">

Example: This Example illustrates the use of method attribute.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body style="text-align:center;">
    <h1 style="color:green;"
    GeeksForGeeks 
</h1>
  
    <h2>DOM Form method Property.</h2>
    <form id="users"
          action="#"
          method="GET" 
          target="_blank">
        First name:
  
        <input type="text" 
               name="fname"
               value="Manas">
  
        <br> Last name:
        <input type="text"
               name="lname"
               value="Chhabra">
  
        <br>
        <input type="submit"
               value="Submit">
    </form>
  
    <p>
      After submitting the form, 
      input values are shown in the address 
      bar of the window.
  </p>
  
    <button onclick="myGeeks()">
      Try it
  </button>
  
    <p id="sudo" 
       style="font-size:25px;
              color:green;">
    </p>
  
    <script>
        function myGeeks() {
  
            // Set property of method. 
            var x =
                document.getElementById("users").method =
                "POST";
            
            document.getElementById("sudo").innerHTML =
                "The value of the method "+
                 "attribute was changed to " + x;
        }
    </script>
  
</body>
  
</html>

chevron_right


Output:

Supported Browsers: The browser supported by HTML Method Attribute are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.