Categories
JavaScript Answers

How to submit two forms with one button with JavaScript?

Spread the love

Sometimes, we want to submit two forms with one button with JavaScript.

In this article, we’ll look at how to submit two forms with one button with JavaScript.

How to submit two forms with one button with JavaScript?

To submit two forms with one button with JavaScript, we call submit on each form on click.

For instance, we write

<input type="button" value="Click Me" onclick="submitForms()" />

to add a button.

We set onclick to submitForms() to call submitForms on click.

Then we write

function submitForms() {
  document.getElementById("form1").submit();
  document.getElementById("form2").submit();
}

to get each form with getElementById and call submit on each form.

Conclusion

To submit two forms with one button with JavaScript, we call submit on each form on click.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *