I have an input for getting password from user :
<input name="Password" id="Password" required/>
in most devices browser will try to autocomplete the password input ( based on saved passwords ),
but lets say we don't want this behavior , **so how could we turn off autocomplete for an input? **
after searching and trying to turn off autocomplete found this solution,
set attribute autocomplete to off :
<input name="Password" id="Password" required autocomplete="off"/>
but it didn't work, when page loads this will happen , i tried JavaScript too but it didn't worked neither
$("#Password").val('')
The solution for Chrome is to add autocomplete="new-password" to the input type password. Please check the example below.
Example:
<form name="myForm"" method="post">
<input name="user" type="text" />
<input name="pass" type="password" autocomplete="new-password" />
<input type="submit">
</form>
Chrome always autocomplete the data if it finds a box of type password, just enough to indicate for that box autocomplete = "new-password".
Note: make sure with CTRL + F5 that your changes take effect. Many times, browsers save the page in the cache.
There are 3 ways you could do this:-
autocomplete = "off"Example:-
<form>
<input type="text" />
<input type="password" autocomplete = "off"/>
<input type="submit">
</form>
autocomplete = "off"Example:-
<form method="post" autocomplete="off">
<input type="text" />
<input type="password" autocomplete = "off"/>
<input type="submit">
</form>
Example:-
<form method="post">
<input type="text" />
<input type="password" autocomplete = "new-password"/>
<input type="submit">
</form>
The first 2 solutions might not work since modern browsers provide a feature to save passwords i.e, they may ask to save the login credentials which will prevent the autocomplete = "off" to act.
For Reference:- https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With