Skip to content
Related Articles
Open in App
Not now

Related Articles

HTML | DOM Input Image formMethod Property

Improve Article
Save Article
  • Last Updated : 26 Aug, 2022
Improve Article
Save Article

The HTML DOM Input Image formMethod Property is used to set or return the value of the form Method Attribute of an Input Image. The formMethod 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. This attribute overrides the method attribute of a <form> element. 

Syntax:

  • It returns the Input Image formMethod property.
imageObject.formMethod
  • It is used to set the Input Image formMethod property.
imageObject.formMethod = get|post

Property 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 is the default value.
  • 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.

Return Value: It returns a string value which represents the HTTP method used to send data while submitting the form. 

Example 1: This example illustrates how to return Input Image formMethod Property. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Image formMethod
    </title>
</head>
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>DOM Input Image formMethod</h2>
    <button onclick="my_geek()">
        <input id="myImage"
            type="image"
            formtarget="#"
            alt="Submit"
            width="48"
            height="48"  formMethod="post"formNoValidate>
    </button>
    <h2 id="Geek_h" style="color:green;">
    </h2>
    <script>
        function my_geek() {
             
            // Return Input Image FormMethod Property
            var txt = document.getElementById(
            "myImage").formMethod;
            document.getElementById(
            "Geek_h").innerHTML = txt;
        }
    </script>
</body>
</html>

Output: 

Before Clicking On Button:

  

After Clicking On Button:

  

Example-2: This Example that illustrates how to set the formMethod Property. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Image formMethod
    </title>
</head>
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>DOM Input Image formMethod Property</h2>
    <button onclick="my_geek()">
        <input id="myImage"
            type="image"
            formtarget="#"
            alt="Submit"
            width="48"
            height="48" formMethod="post"formNoValidate>
    </button>
    <h2 id="Geek_h" style="color:green;">
    </h2>
    <script>
        function my_geek() {
             
            // set Input Image formmethod Property
            var txt = document.getElementById(
            "myImage").formMethod = "Get";
            document.getElementById(
            "Geek_h").innerHTML =
            "The value of the formMethod Attribute was changed to "
             + txt;
        }
    </script>
</body>
</html>

Output: 

Before Clicking On Button:

 

After Clicking On Button:

  

Supported Browsers: The browsers supported by DOM Input Image formMethod Property are listed below:

  • Google Chrome
  • Edge 12+
  • Firefox
  • Apple Safari
  • Opera

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!