// Get the form element
const form = document.getElementById('myForm');
// Add a form submit event listener
form.addEventListener('submit', function(event) {
event.preventDefault(); // Prevent form submission
// Serialize form data into a JSON object
const formData = {};
new FormData(form).forEach((value, key) => {
formData[key] = value;
});
// Access and log the values
const name = formData.name;
const email = formData.email;
console.log(`Name: ${name}, Email: ${email}`);
});