Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two forms, one submit button [duplicate]

I have two forms, I need one submit button for two forms. How I can do it, without ajax?

<form action="" id="form" method="post">
    <input type="file" name="file">
    <input type="text" name="text">
</form>

<form action="" id="form2" method="post">
    <input type="file" name="file">
    <input type="text" name="text">
</form>

I know that this topic has been raised more than once, but it's not a duplicate, as I need it without ajax

like image 494
Mykyta Dudariev Avatar asked Feb 12 '26 22:02

Mykyta Dudariev


1 Answers

You can use Document.forms which returns a collection.Thereafter forms[0] will return the first form from DOM and so on .Then you can use one button to submit the forms

<button type = "button" onclick="submitForm()">Submit</button>

function submitForm(){
    document.forms[0].submit();
    document.forms[1].submit();
}
like image 75
brk Avatar answered Feb 15 '26 10:02

brk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!