Open In App

HTML | DOM Form autocomplete Property

Last Updated : 31 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The Form autocomplete property in HTML DOM is used to set or return of the autocomplete attribute. The autocomplete attribute is used to specify whether the autocomplete attribute has “on” or “off” value. When the autocomplete attribute is set to on so the browser will automatically complete the values base on which the user entered before.

Syntax:

  • It is used to return the autocomplete property.
    formObject.autocomplete
  • It is used to set the autocomplete property.
    formObject.autocomplete = on|off
  • Property Values:

    • on: It is the default value. It automatically complete the values.
    • off: It defines that the user should fill all the values of the input field. It dopes not automatically complete the values.

    Return Value: It returns a string value which represent the state of autocomplete attribute.

    Example 1: This HTML Program illustrates how to return the property.




    <!DOCTYPE html> 
    <html
      
    <head>
        <title>
            HTML DOM Form autocomplete Property
        </title>
    </head>
      
    <body>
           
        <h1>GeeksForGeeks</h1>
          
        <h2>DOM Form autocomplete Property</h2>
          
        <form action="#" method="post" id="users" autocomplete="on"
              
            <label for="username">Username:</label
              
            <input type="text" name="username" id="Username"> <br>
              
            <label for="password">Password:</label
              
            <input type="password" name="password" id ="password"><br><br>
        </form
          
        <button onclick="myGeeks()">Submit</button>
          
        <p id="GFG"></p>
          
        <!-- Script to display autocomplete value -->
        <script>
        function myGeeks() {
            var auto_comp = document.getElementById("users").autocomplete;
            document.getElementById("GFG").innerHTML = auto_comp;
        }
        </script>
    </body
      
    </html>                                    

    
    

    Output:
    Before Click on the Button:

    After Click on the Button:

    Example 2: This example set the form autocomplete to off.




    <!DOCTYPE html> 
    <html
      
    <head>
        <title>
            HTML DOM Form autocomplete Property
        </title>
    </head>
      
    <body>
           
        <h1>GeeksForGeeks</h1>
          
        <h2>DOM Form autocomplete Property</h2>
          
        <form action = "#" method="post" id="users" autocomplete="on"
              
            <label for="username">Username:</label
            <input type="text" name="username" id="Username"> <br>
              
            <label for="password">Password:</label
            <input type="password" name="password" id ="password"><br><br>
        </form
          
        <button onclick="myGeeks()">Submit</button>
          
        <p id="GFG"></p>
          
        <script>
        function myGeeks() {
            var x = document.getElementById("users").autocomplete = "off";
              
            document.getElementById("GFG").innerHTML
                    = "Now the autocomplete is set to " + x;
        }
        </script>
    </body
      
    </html>                    

    
    

    Output:
    Before Click on the Button:

    After Click on the Button:

    Supported Browsers: The browser supported by DOM Form autocomplete property are listed below:

    • Google Chrome 14
    • Edge 12
    • Firefox 4
    • Opera 15
    • Safari 6


    Like Article
    Suggest improvement
    Previous
    Next
    Share your thoughts in the comments

Similar Reads