I have two forms in my html file. They both submitted by one button. Can I connect both forms with this button? Something like
<button form="firstFormId secondFormId"> Save </button>.
Will it make any sense?
I have two forms in my html file. They both submitted by one button.
Share
You have multiple solutions to do that, I’d go with javascript, or even better, jQuery, if you’re using it.
If you are not using jquery, with javascript you could do something like this:
Place somewhere in the page a “submit” link:
Assign to each form an unique name, let’s say “myform1” and “myform2”.
Then include in your page the following:
Instead of calling an external function, to keep things as simple as possible, after assigning the names to the forms, you could even simply place the following link:
If you are using jQuery, and I suggest this way, you could simply assign a given class to both forms, let’s say “submit-me” and then add to your code:
Of all the above I would definitely suggest the last one, that relies on jQuery. It’s easy to maintain, reusable (meaning that it can be applied to any form having the class
submit-me, and all the job is done by jQuery.Note that in all the examples you don’t need anymore the “classic” submit button of forms.
Not tested, but I hope it’ll do what required! 🙂