How to detect if HTML form is edited with JavaScript?

Spread the love

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 listen to the forms’ input event.

For instance, we write

const form = document.getElementById("myForm");

form.addEventListener("input", () => {
  console.log("Form has changed!");
});

to select the form with getElementById.

Then we listen to the input event with addEventListener.

If it’s emitted, then the form has been edited.

Conclusion

To detect if HTML form is edited with JavaScript, we listen to the forms’ input event.

Leave a Reply

Your email address will not be published. Required fields are marked *