0

I have 2 separate forms in HTML and want to send them via a single button. How can I do that? When I try to make them into one form by removing the start and end in the middle, the div tags and CSS messes up. Here is my code.

            <div class="contact-bottom"> 
            <div class="col-md-6 contact-left"> 
            <form>
                <input type="text" placeholder="Name" required="">
                <input type="text" placeholder="E-mail" required="">
                <input type="text" placeholder="Phone" required="">
            </form>
            </div>
            <div class="col-md-6 contact-left">
            <form>
                <textarea placeholder="Message"></textarea>
                <input type="submit" value="SEND">
            </form> 
            </div>
            <div class="clearfix"> </div>
        </div>
  • 3
    broken css is not a good reason to split form... if both forms need to be submitted with the same button, then they should be in the same form... maybe you can post a new question to fix up your css, instead of splitting it in two forms and using a complex solution to submit two forms with one button. – Hooman Bahreini Dec 13 '17 at 23:50
  • 1
    Exactly - as this is related to your page's layout, it's a CSS issue rather than a JS one – Ben Kolya Mansley Dec 13 '17 at 23:54
  • Possible duplicate of [Submit two forms with one button](https://stackoverflow.com/questions/7843355/submit-two-forms-with-one-button) – Shawn J. Molloy Dec 14 '17 at 00:07
  • 1
    There's no point in having two forms like in your example – j08691 Dec 14 '17 at 00:59

1 Answers1

0

Use ajax to post values !

Exemple:

   <script>
      $(document).ready(function(){
        $("#submit").click(function(){
            $.ajax({
                        type: 'post',
                            url: "mail.php",
                        data:  { "name" : $("#mail-name").val() ,"email" :  $("#mail-email").val() },
                        success: function($response) {
                alert($response);
            }
            });

        });
      });
  • It's not necessary that both the forms inputs will be submitted to the same script, if that was the case then two forms wouldn't be required in the first place. –  Dec 13 '17 at 23:56