0

I have two HTML forms on one page. I am copying the data from the first form #MemberForm to another form which won't be visible in the end #InvisibleForm. I can't seem to get the two forms to submit together at the same time.

First I have some jQuery copying the data from the first form to the second form when I hit submit:

$(function() {
  $('#catupdatedetailsformbutton').click(function() {
    var form1 = $('#MemberForm').find(':input');
    var form2 = $('#InvisibleForm');
    form1.each(function() {
      var $t = $(this);
      form2.find('[name="' + $t.attr('name') + '"]').val($t.val());
    });
  });
});

I'm not aware of how to submit two forms with any jQuery but I wrote up some JS that isn't working. I've placed it after the jQuery with an onclick="submitForms()" in the submit button but it doesn't submit both forms.

submitForms = function() {
  document.getElementById("MemberForm").submit();
  document.getElementById("InvisibleForm").submit();
}

Am I missing something? Can someone point me in the right direction? I've never attempted something like this before!

Mi-Creativity
  • 9,554
  • 10
  • 38
  • 47
Trees
  • 9
  • 5
  • 1
    You cannot submit two forms at the same time, unless you use AJAX. – Rory McCrossan Feb 10 '16 at 07:56
  • Check [this out](http://stackoverflow.com/a/8563735/3509874) – urbz Feb 10 '16 at 07:57
  • 2
    @RoryMcCrossan - unfortunately there is floating accepted answers like this around -> http://stackoverflow.com/a/7843397/1407478 not surprising if people who have less experience and try to find an answer gets confused. – davidkonrad Feb 10 '16 at 08:00
  • 1
    @davidkonrad thanks. I've flagged that one as it's completely wrong. How it got accepted I don't know as it was never the case where that code would work, even 5 years ago. – Rory McCrossan Feb 10 '16 at 08:03

0 Answers0