Created
March 29, 2024 17:29
-
-
Save jamesmurdza/3cc584240ec40c3d257a3b8be4773145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Select all forms on the page | |
const forms = document.querySelectorAll('form'); | |
// Iterate over each form and attach a submit event listener | |
forms.forEach(form => { | |
form.addEventListener('submit', event => { | |
event.preventDefault(); // Prevent the default form submission behavior | |
// Get form data | |
const formData = new FormData(form); | |
// Convert FormData to object | |
const formObject = {}; | |
formData.forEach((value, key) => { | |
formObject[key] = value; | |
}); | |
// Log the form data | |
console.log('Form Data:', formObject); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment