Javascript Reference - HTML DOM Form autocomplete Property








The autocomplete property sets or gets the autocomplete attribute in a form.

When autocomplete is on, the browser fills values based on values that the user has entered before.

Browser Support

autocomplete Yes Yes Yes Yes Yes

Syntax

Return the autocomplete property.

var v = formObject.autocomplete

Set the autocomplete property.

formObject.autocomplete=on|off




Property Values

Value Description
on Default value. The browser will complete values based on values that the user has entered before
off The browser does not automatically complete entries

Return Value

A String type value representing the state of autocompletion.

Example

The following code shows how to get the state of autocompletion.


<!DOCTYPE html>
<html>
<body>
<!-- ww w .  j av a  2  s. c  om-->
<form id="myForm" action="url" autocomplete="on">
  First name:<input type="text" name="fname"><br>
  E-mail: <input type="email" name="email"><br>
  <input type="submit">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myForm").autocomplete;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to turn autocomplete off.


<!DOCTYPE html>
<html>
<body>
<!--   w w w.j av  a2  s. co m-->
<form id="myForm" action="url" autocomplete="on">
  First name:<input type="text" name="fname"><br>
  E-mail: <input type="email" name="email"><br>
  <input type="submit">
</form>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myForm").autocomplete = "off";
}
</script>
</body>
</html>

The code above is rendered as follows: