#CHECK VALIDITY

6 messages · Page 1 of 1 (latest)

hollow sphinx
#

I made a data entry site with two faces,
front containing personal info and back containing medical info (you can flip the card),
I have a button in the back face but how do I make the button validate and submit both of them cards?

hollow sphinx
#

the prevent default isn't working either

hollow sphinx
#

still no

errant shoal
#

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

errant shoal
#

(not sure about the relevance of the topic "check validity" though)