#CHECK VALIDITY
6 messages · Page 1 of 1 (latest)
the prevent default isn't working either
You do not need submit listeners on both sides.
Instead I'd write a function to collect the data and handle them. call this function on click on the submit button.
function submitForm() {
// create a FormData Object for each side's entries
const data1 = new FormData(form1);
const data2 = new FormData(form2);
// combine form data from both sides - need to convert to JS objects
const combinedFormData = {
...Object.fromEntries(data1),
...Object.fromEntries(data2)
};
// submit and or store the combined form data - here in localStorage
localStorage.setItem("formData", JSON.stringify(combinedFormData));
console.log("Form data submitted successfully!");
console.table(combinedFormData);
}
This is just locally.
More examples for an async use:
https://javascript.info/formdata
(not sure about the relevance of the topic "check validity" though)