Related Articles

Related Articles

HTML | DOM Form autocomplete Property
  • Last Updated : 11 Feb, 2019

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.



    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:
    Before Click on the Button:

    After Click on the Button:

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

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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
    • Internet Explorer
    • Firefox
    • Opera
    • Safari

    full-stack-img




    My Personal Notes arrow_drop_up
Recommended Articles
Page :