HTML | DOM Input Image name Property

The HTML DOM Input Image name Property is used for setting or returning the value of the name attribute of the Input Image. The name Attribute is used to reference the form-data after submitting the form or to reference the element in a JavaScript.

Syntax:

  • To returns the name Property:
    imageObject.name
  • To sets the name Property:
    imageObject.name

Property Values: Accepts a single parameter name and it specify the name of the Input Image.



Return Value: It returns a string value which represent the name of the Input Image.

Example 1: This program illustrate how to return the name Property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM Input Image name Property
    </title>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;"
      GeeksforGeeks 
    </h1>
  
    <h4>
      DOM Input Image name Property
    </h4>
    <button onclick="my_geek()">
        <input id="myImage" name="myGeeks" type="image" src=
               alt="Submit" formaction="#" a formtarget="#" 
               formenctype="text/plain" width="48" height="48">
    </button>
    <h2 id="Geek_h" style="color:green;"></h2>
    <script>
        function my_geek() {
  
            // Return formTarget, formEnctype and formAction. 
            var txt = document.getElementById(
                "myImage").name;
            document.getElementById("Geek_h").innerHTML = txt;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before Clicking On Button:
  • After Clicking On Button:

Eample 2: This Example illustrate how to sets the name Property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM Input Image name Property
    </title>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;"
      GeeksforGeeks 
    </h1>
  
    <h4>
      DOM Input Image name Property
    </h4>
    <button onclick="my_geek()">
        <input id="myImage" name="myGeeks" type="image" src=
               alt="Submit" formaction="#" a formtarget="#" 
               formenctype="text/plain" width="48" height="48">
    </button>
    <h2 id="Geek_h" style="color:green;"></h2>
    <script>
        function my_geek() {
  
            // Return formTarget, formEnctype and formAction. 
            var txt = document.getElementById(
                "myImage").name = 
                "The value of the name attribute was changed to "
                                                  + "Hello Geeks";
            document.getElementById("Geek_h").innerHTML = txt;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before Clicking On Button:
  • After Clicking On Button:

Supported Browsers: The browsers supported by HTML | DOM Input Image name Property 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.



Improved By : shubham_singh



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.