Code Snippets
Login
Forms: adjustable form input reader
Don't forget to rename the fields :D
Label
const FORM_NAME = document.getElementById("FORM_NAME"); const formElements = contactForm.querySelectorAll("input, textarea"); // don't forget to add new input types if we need to add to the current form const submitButton = document.querySelector("input[type=submit]"); const formData = {}; formElements.forEach(element => { const key = element.id if (key) { formData[key] = element; element.addEventListener("input", validateForm); // calls the form validation function - rename as required } });
Copy to clipboard
Copied!
©
Leerlandais 2024