Javascript DOM HTML Input Text autocomplete Property

Introduction

Set autocomplete in a text field to off:

document.getElementById("myText").autocomplete = "off";

Click the button to set autocomplete in the text field to "off".

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Name: <input type="text" id="myText" name="fname" autocomplete="on">
  <input type="submit">
</form>//  w w w. jav  a  2  s. co m


<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("myText").autocomplete = "off";
  document.getElementById("demo").innerHTML = "autocomplete is now 'off'.";
}
</script>

</body>
</html>

The autocomplete property sets or gets the autocomplete attribute in a text field.

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

Value Description
onDefault. The browser will automatically complete values
off The browser does not automatically complete entries



PreviousNext

Related