Submitting two forms with one processing file to the database in express

May it will be better to set “submit” action on form (as result remove tags)

const elemetns = {
    equipmentsForm: document.getElementById('equipments') <== set this id to form,
    materialsForm: document.getElementById('materials') <== set this id to form

after add submit to each form

elemetnts.equipmentsForm.submit(e => processForm(e, elemetnts.equipmentsForm, someRoute))
elemetnts.materialsForm.submit(e => processForm(e, elemetnts.materialsForm, someRoute))

after it create “processForm” func

  fucntion processForm (e, form, route) {
    const data = new FormData(form);

    type: "POST",
    url: route,
}).done(() => console.log('success'));

here i use $.ajax. But you can use new XMLHttpRequest() constructor. Find out how create XMLHttpRequest.

so, i think, it is enought to solve your case.

Best regards!

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top