admin管理员组

文章数量:1406949

For example, say I have these two forms

<form method="post" action="/lorum/ipsum/dolor/sit/amet">
<!-- Some stuff --> 
</form>
<form method="post" action="some/other/location/here">
<!-- Some stuff --> 
</form>


<button> </button> <!-- this is going to submitboth forms 

For example, say I have these two forms

<form method="post" action="/lorum/ipsum/dolor/sit/amet">
<!-- Some stuff --> 
</form>
<form method="post" action="some/other/location/here">
<!-- Some stuff --> 
</form>


<button> </button> <!-- this is going to submitboth forms 

I hope this makes sense

Share asked May 3, 2018 at 14:29 Lewis ClarkeLewis Clarke 692 silver badges13 bronze badges 2
  • You can write javascript to handle click on the button and make requests manually. – Jagdeep Singh Commented May 3, 2018 at 14:31
  • 1 why would you do that ? what are you trying to achieve ? – Muhammad Usman Commented May 3, 2018 at 14:32
Add a ment  | 

2 Answers 2

Reset to default 5

Something like that works:

document.getElementById("submit").onclick = function() {
  document.getElementById("form1").submit();
  document.getElementById("form2").submit();
}
<form id="form1" method="post" action="/lorum/ipsum/dolor/sit/amet">
  <!-- Some stuff -->
</form>
<form id="form2" method="post" action="some/other/location/here">
  <!-- Some stuff -->
</form>

<button id="submit">Submit forms</button>

I don't know how to test it, but I'll try to update my snippet if I found. :)

Hope it helps.

this code works.

<SCRIPT LANGUAGE="JavaScript">

<!--

function SubmitBoth()

{

document.frm1.submit();
document.frm2.submit();
}
//-->
</SCRIPT>

<form name="frm1" target="formresponse1" action="send1.php" method="post">
</FORM>

<form name="frm2" target="formresponse2" action="send2.php" method="post">
</FORM>


<INPUT TYPE="button" value="SubmitBoth" onClick="SubmitBoth()">

<iframe name='formresponse1' width='300' height='200'></frame>
<iframe name='formresponse2' width='300' height='200'></frame>

maybe someone else will tidy it up!

本文标签: javascriptCan I submit two forms with one buttonStack Overflow