Each browser has a built in functionality to store the form data submitted by the user to auto fill the similar form at a later stage. Of course, user can disable this. But what if a user is opening your web page, which has a text field with auto complete functionality that you've implemented. Ideally, user should get the suggestions of the auto complete that you've implemented and not his previous form data that he has submitted.

Sometimes as a programmer you'll be in the scenario that, you don't want to show the browser cache data (form data). i.e.; if you've already provided the auto complete for the input field, you definitely want to remove the existing browser auto complete functionality.

Include the below script on the page and invoke that for your form.


//This function is to set the auto complete off for the first form
function autocompleteOff(element) {
self.focus(); //Bring window to foreground if necessary.
var form = document.getElementById(element); //grab the form element.
if(form){
form.setAttribute("autocomplete","off"); // Turn off Autocomplete for the form, if the browser supports it.
form.elements[0].focus(); // Send the cursor to the first field of the first form
}
}
Example, if you've a form with the id "userform", you should invoke this as below
autocompleteOff("userform");
You can read my other Javascript articles/programs.