Set autocomplete to off:
document.getElementById("myForm").autocomplete = "off";
Click button to set autocomplete in the form element to "off".
<!DOCTYPE html> <html> <body> <form id="myForm" action="/action_page.php" autocomplete="on"> First name:<input type="text" name="fname"><br> E-mail: <input type="email" name="email"><br> <input type="submit"> </form>//w w w . ja v a 2 s. c o m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myForm").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 form.
We can use autocomplete "on" for the form, and "off" for specific input fields, or vice versa.
The autocomplete
property accepts and returns a String type value.
Property Values
Value | Description |
---|---|
on | Default. The browser will automatically complete values |
off | The browser does not automatically complete entries |
The autocomplete
property returns a String representing the state of auto completion.