HTML | DOM Input Hidden Object

The Input Hidden object in HTML DOM represents the <input> element with type = “hidden” attribute. The element can be accessed by using getElementById() method.

Syntax:

document.getElementById("id"); 

where id is assigned to the <input> tag.

Property Values:

  • defaultvalue: It is used to set or return the default value of a hidden input field.
  • form: It returns the reference of form that contains the hidden input field.
  • name: It is used to set or return the name attribute value of a hidden input field.
  • type: It returns the type of form element the hidden input field belongs.
  • value: It is used to set or return the value of the value attribute of a hidden input field.

Example 1: This example describes the getElementById() method to access the <input> element with type = “hidden” attribute.

filter_none

edit
close

play_arrow

link
brightness_4
code

   
<html
<head
<title> DOM Input Hidden Object </title
</head
<body
    <center>
        <h1 style = "color:green;">
            GeeksForGeeks
        </h1>
           
        <h2>DOM Input Hidden Object</h2>
           
        <input type = "hidden" id = "myGeeks"
                    value="GeeksForGeeks">
           
        <button onclick = "Geeks()">
            Submit
        </button>
           
        <p id = "sudo"></p>
           
        <script>
            function Geeks() {
                var g = document.getElementById("myGeeks").value; 
                document.getElementById("sudo").innerHTML = g; 
            }
        </script>
    </center>
</body>
   
</html>        
  

chevron_right


Output:
Before Click on the Button :

After Click on the Button :

Example 2: Input Hidden Object can be created by using the document.createElement method.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        DOM Input Hidden Object
    </title>
</head>
  
<body>
    <center>
        <h1 style = "color:green;">
            GeeksForGeeks
        </h1>
          
        <h2>DOM Input Hidden Object</h2>
          
        <input type = "hidden" id = "myGeeks"
                    value="GeeksForGeeks">
          
        <button onclick = "Geeks()">
            Submit
        </button>
          
        <p id = "sudo"></p>
          
        <script>
            function Geeks() {
                var g = document.createElement("INPUT");
                g.setAttribute("type", "hidden");
                document.body.appendChild(g);
                  
                document.getElementById("sudo").innerHTML
                        = "Hidden Content";
            }
        </script>
    </center>
</body>
  
</html>                    

chevron_right


Output:
Before Clicking On Button:

After Clicking On Button:

Supported Browsers: The browser supported by DOM Input Hidden Object 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.