Jquery submit multiple forms in a page

jquery

Solution

I would suggest putting a class on every input button you wish to submit like this.

For example you could have some forms like this:

<form id="form1">
  <!--Form elements-->
  <input class="submitButton" type="button" value="submit" />
</form>
<form id="form2">
  <!--Form elements-->
  <input class="submitButton" type="button" value="submit" />
</form>

You could then use jQuery to submit them like this:

$(".submitButton").click(function() {

  //Select the parent form and submit
  $(this).parent("form").submit();

});

Problem

I searched and found the nice code from here. Submit a form using jQuery ``` <input type='button' value='Submit form' onClick='submitDetailsForm()' /> <script language ="javascript" type = "text/javascript" > function submitDetailsForm() { $("#formId").submit(); } </script> ``` But can you please advise how to deal with multiple form within a page such? ``` <form id="myForm1" action="comment.php" method="post"></form> <form id="myForm2" action="comment.php" method="post"></form> <form id="myForm3" action="comment.php" method="post"></form> <form id="myForm4" action="comment.php" method="post"></form> ```

Original source

Related problems