Sometimes, we want to detect if HTML form is edited with JavaScript.
In this article, we’ll look at how to detect if HTML form is edited with JavaScript.
How to detect if HTML form is edited with JavaScript?
To detect if HTML form is edited with JavaScript, we can listen to the input
event.
For instance, we write
const form = document.getElementById("myForm");
form.addEventListener("input", () => {
console.log("Form has changed!");
});
to select a form element with getElementById
.
Then we call addEventListener
to listen to the input event on the form.
It’s triggered if the form’s fields have been changed.
Conclusion
To detect if HTML form is edited with JavaScript, we can listen to the input
event.