How to disable auto-complete in HTML Form input field?


Hello, I would like to know, how I can disable HTML form input field auto-complete, done by chrome and other majore browsers.

Thanks


Asked by:- jaiprakash
1
: 1721 At:- 12/21/2018 12:08:32 PM
HTML autocomplete off







2 Answers
profileImage Answered by:- jaya

You can have two ways to stop auto-complete of forms input field by:

1. Add autocomplete="off" onto <form> element

<form method="post" action="/form" autocomplete="off">
     First name:<input type="text" name="fname"><br>
     Last name: <input type="text" name="lname"><br>
</form>

2. OR you can disable auto complete on a particular form input field

<input type="email" name="email" autocomplete="off">

Any of the above will work and you can use it depending on your requirements.

3. instead of setting autocomplete=off, you could also have your form field names be randomized by the code that generates the page and on server-side, once form is submitted, you can strip that random generated code to get values.

This approach also helps you from XSRF attack, as hacker cannot know your fields names

2
At:- 12/23/2018 5:00:32 PM Updated at:- 9/24/2022 12:53:08 AM
Thanks, It solved my issue. 0
By : jaiprakash - at :- 5/6/2020 11:14:38 AM


profileImage Answered by:- vikas_jk

Above solution works but chrome will still not turn off auto-complete for password fields so solution for Chrome is to add autocomplete="new-password" to the input type password. 

<form name="myForm"" method="post">
   <input name="user" type="text" />
   <input name="pass" type="password" autocomplete="new-password" />
   <input type="submit">
</form>

Also, to note, this will work for other type of fields also in chrome, something like this

<input name="name" type="text" autocomplete="rutjfkde">

hope it helps.

0
At:- 4/26/2022 3:33:45 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use