Related Articles

Related Articles

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.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!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

chevron_right


Output:
Before Clicking On Button:

After Clicking On Button:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


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

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :