How to detect if HTML form is edited?

Spread the love

To detect if HTML form is edited, we listen to the input event.

For instance, we write

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

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

to get the form element with getElementById.

Then we call addEventListener to add an input event listener.

When the form is changed, the input event is emitted and the event listener function is called.

Leave a Reply

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