anthonyro
anthonyro

Reputation: 109

Disable input field autofill (pure JS)

Does anyone know how to disable input autofill/autocomplete in 2021 using pure JS?

I've tried:

<input type="password" autocomplete="off" />
<input type="password" autofill="off" />
<input type="password" autocomplete="new-password" />
<input type="password" autofill="none" />

etc.

Also tried using jquery.disable-autofill and npm disableautofill from the stackoverflow solutions

Gonna be good if someone can share some more solutions

Upvotes: 1

Views: 1683

Answers (2)

nxt
nxt

Reputation: 436

Try This Solution in JS

clearAutoFIll();

function clearAutoFIll(){
  var inp = document.querySelectorAll("[autocomplete=off] input");
  for(var x=0; x < inp.length; x++){
    inp[x].value = "";
  }
}
<form autocomplete=off>
  <input type=text name="phone" />
</form>

Upvotes: 2

Mudassar Abbas
Mudassar Abbas

Reputation: 176

one more thing we can use autocomplete in form tag also like see below

<form action="/form/submit" method="get" autocomplete="off">

Or In JS

    $(function() {
      setTimeout(function() {
        $("input").val("");
      }, 500);
   });

Upvotes: 4

Related Questions