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.
autocomplete |
Yes | Yes | Yes | Yes | Yes |
Return the autocomplete property.
var v = formObject.autocomplete
Set the autocomplete property.
formObject.autocomplete=on|off
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 |
A String type value representing the state of autocompletion.
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:
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: