My problem is that after writing this code:
const form = document.getElementById(‘form’);
function handleSubmit(event) {
event.preventDefault();
}
const data = {};
const fields = event.target.querySelectorAll(‘input, select, textarea’);
for (const field of fields) {
data[field.name] = field.value;
}
form.addEventListener(‘submit’, handleSubmit);
It shows this type error: TypeError: Cannot read properties of undefined (reading ‘target’)https://fc349b7a-5180-4c97-9432-82f7df6d86fe-00-b9jrwad18xpf.pike.replit.dev/script.js:8
I was trying to do a form validation course from frontend mentor and this happened