Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Input Image formMethod Property

  • Last Updated : 27 Aug, 2019

The HTML DOM Input Image formMethod Property Syntax: 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.
  • 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.






<!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 target, alt and height. 
            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.




<!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() { 
              
            // Return target, alt and height. 
            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
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :