Javascript DOM HTML Input Search autocomplete Property set

Introduction

Set autocomplete in a search field to off:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Search: <input type="search" id="mySearch" name="search" autocomplete="on">
  <input type="submit">
</form>// w w w.  j  av  a  2  s  . c  o m
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

The autocomplete property sets or gets the value of the autocomplete attribute in a search field.

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

The autocomplete property accepts and returns a String type value.




PreviousNext

Related