Skip to content
Related Articles

Related Articles

HTML | DOM Input Reset Object
  • Last Updated : 06 Feb, 2019
GeeksforGeeks - Summer Carnival Banner

The Input Reset Object in HTML DOM is used to represent the HTML <input> element with type=”reset”.
This tag is used to access or create the <input> element. This element can be accessed by using getElementById() method.

Syntax:

document.getElementById("Input_ID");

This Input_ID is assigned to HTML <input> element.

Example-1: Creating <input> element with type = “reset”.




<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM RESET Object
    </title>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">  
            GeeksForGeeks  
        </h1>
  
    <h2>DOM Reset Object</h2>
  
    <button onclick="myGeeks()">
        Click Here
    </button>
  
    <script>
        function myGeeks() {
            // creating input element with type = "reset"
            var x = document.createElement("INPUT");
            x.setAttribute("type", "reset");
            document.body.appendChild(x);
        }
    </script>
</body>
  
</html>

Output:



  • Before click on the button:
  • After click on the button:

Example-2: Returning value of <input> element from “GeekReset” id using document.getElementById(“GeekReset”)




<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM RESET Object
    </title>
</head>
<style>
    #Geek_p {
        font-size: 30px;
        color: green;
    }
</style>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">  
            GeeksForGeeks  
        </h1>
  
    <h2>DOM Reset Object</h2>
    <input type="reset" 
           id="GeekReset" 
           value="Reset form">
    <br>
    <br>
    <button onclick="myGeeks()">
        Click Here
    </button>
    <p id="Geek_p"></p>
    <script>
        function myGeeks() {
            // access input element with type = "reset"
            var x = 
             document.getElementById("GeekReset").value;
            document.getElementById("Geek_p").innerHTML = 
            x;
        }
    </script>
</body>
  
</html>

Output:

  • Before click on the button:
  • After click on the button:

    Example-3: Returning id of input element with type=”reset”.




    <!DOCTYPE html>
    <html>
      
    <head>
        <title>
            HTML DOM RESET Object
        </title>
    </head>
    <style>
        #Geek_p {
            font-size: 30px;
            color: green;
        }
    </style>
      
    <body style="text-align:center;">
      
        <h1 style="color:green;">  
                GeeksForGeeks  
            </h1>
      
        <h2>DOM Reset Object</h2>
        <input type="reset" 
               id="GeekReset"
               value="Reset form">
        <br>
        <br>
        <button onclick="myGeeks()">
            Click Here
        </button>
        <p id="Geek_p"></p>
        <script>
            function myGeeks() {
                // access input element with type = "reset" 
                var x =
                document.getElementById("GeekReset").id;
                document.getElementById("Geek_p").innerHTML =
                  x;
            }
        </script>
    </body>
      
    </html>

    Output:

    • Before click on the button:
    • After click on the button:

    Note: type=”reset” is use to reset all value to it’s initial value using “Reset Button”.

    Supported Browsers:

    • Google Chrome
    • Mozilla Firefox
    • Edge
    • Safari
    • Opera

    full-stack-img

    My Personal Notes arrow_drop_up
Recommended Articles
Page :