Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events support #137

Open
ghost opened this issue Aug 6, 2019 · 1 comment
Open

Events support #137

ghost opened this issue Aug 6, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 6, 2019

It would be nice to have some sort of events support to know when the form was changed (new elements added, or user typed any text).

@peeyush12345
Copy link

<title>Form Event Tracking</title> <script> document.addEventListener("DOMContentLoaded", function() { // Get a reference to the form var form = document.getElementById("myForm");
  // Add event listeners to form elements
  var formElements = form.elements;
  for (var i = 0; i < formElements.length; i++) {
    formElements[i].addEventListener("change", handleFormChange);
  }

  // Event handler for form change
  function handleFormChange(event) {
    // Get the changed form element
    var changedElement = event.target;
    console.log("Form element changed:", changedElement);

    // Perform desired actions based on the change
    // For example, you can check if it's a new element being added
    if (changedElement.tagName === "INPUT" && changedElement.type === "text") {
      console.log("New text input element added:", changedElement);
    }

    // You can also check if the user typed any text
    if (changedElement.tagName === "INPUT" && changedElement.type === "text" && changedElement.value !== "") {
      console.log("User typed text:", changedElement.value);
    }

    // Add more conditions or actions as per your requirements
  }
});
</script>

<textarea name="message" placeholder="Message"></textarea>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant