const form = document.querySelector("#contact-form");
const feedback = document.querySelector(".feedback");
const patternName = /^[a-z A-Z]{3,25}$/;
form.addEventListener("submit", (e) => {
e.preventDefault();
const firstname = form.firstname.value;
if (patternName.test(firstname)) {
console.log(firstname);
feedback.textContent = "";
form.reset();
resetInputHistory();
} else {
console.log("invalid");
feedback.textContent =
"Name field must not contain special characters or numbers and should not be less than three letters.";
}
function resetInputHistory() {
const inputFields = form.querySelectorAll("input");
inputFields.forEach((input) => {
input.autocomplete = false;
});
}
});
I have tried setting the input.autocomplete statement to both false and "off", yet field still shows all the previous input history.
2
Answers
Solution without JavaScript
you can see i use autocomplete (on) on my form and i also use autocomplete (off) on my email input tag inside the form. if you type any name in name input tag and submit after the reload the autocomplete work on that but if you try this for the email tag then autocomplete not work… so you can doing this from the HTML without using JavaScript….
In your code, you’re already setting input.autocomplete to false, but that may not have the desired effect in all browsers.
try setting it to "off"