1

I have two different forms. Each of them has its own submit button

<input type="submit" id="edit-submit" name="op" value="Submit" class="form-submit ajax-processed">

and

<input type="submit" id="edit-submit--2" name="op" value="Submit" class="form-submit ajax-processed">

I need to make a separate button that would click on these two input. How can I do this?

  • 1
    You need what now? A button that submit both forms? – Ole Haugset Oct 09 '14 at 12:19
  • Create a one button, which submit two forms. –  Oct 09 '14 at 12:22
  • 2
    Look at: http://stackoverflow.com/questions/7843355/submit-two-forms-with-one-button and http://stackoverflow.com/questions/9403160/submit-two-forms-in-1-button – Tobías Oct 09 '14 at 12:24
  • I try so: ` ` But it does not work. –  Oct 09 '14 at 12:33
  • It only submit the first one ? Sounds pretty normal to me – TCHdvlp Oct 09 '14 at 12:41
  • @Pearson you have to submit one of them using Ajax. – Amy Oct 09 '14 at 12:52
  • You are goign to have to make some kind of ajax solution , or how about ... combinning these 2 forms into one, since it seems that would work better anyways – Scott Selby Oct 09 '14 at 13:39

2 Answers2

0

If you have more than 2 forms and only want 2 of them to be submited, they must have a common part, like a css class (no styling here, only a selector).

HTML part :

<form id="form1" class="myForm ..."/>
<form id="form2" class="myForm ..."/>
<input type="button" id="myButton" value="Submit both forms"/>

js :

$("#myButton").click(function(){
    $(".myForm").submit();
});

You can add as many form as you want, if they have the class myForm, they will be submited too. No need to change your js code...

TCHdvlp
  • 1,334
  • 1
  • 9
  • 15
0

Just provides the ids to your form.for example:

<form id="form1" class="myForm ..."/>
<form id="form2" class="myForm ..."/>

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

<script>
   submitForms = function(){
     document.getElementById("form1").submit();
     document.getElementById("form2").submit();
   }
</script>
Priyank
  • 3,778
  • 3
  • 29
  • 48