B
B
barbosk2021-06-15 15:40:41
JavaScript
barbosk, 2021-06-15 15:40:41

How to link one form to another?

<form id='form1'>
 <input type='text' name='text1'>
<a  href="#form2">Ссылка</a>
</form>

<form id='form2'>
 <input type='text' name='text2'>
<button type='submit'>Отправить форму </button>
</form>


How can I connect the 1st form with the button of the 2nd, so that the filled data from the 1st and 2nd forms are combined and sent? The 1st form calls a modal with another form

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Markov, 2021-06-15
@b4rbos

I haven't tested it but I think it should work.

const formData1 = new FormData( document.getElementById('form1') );
const formData2 = new FormData( document.getElementById('form2') );
for(const [key, value] of formData2.entries()) {
    formData1.append(key, value)
}
return formData1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question