Can I submit form with multiple submit buttons using jQuery?



Yes, you can submit form with multiple submit buttons. Attack a custom click handler to all the buttons and the check which button is clicked.

Example

Live Demo

<!DOCTYPE html> <html>   <head>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>     <script>     $(document).ready(function(){       $("#myform button").click(function (ev) {       ev.preventDefault()       if ($(this).attr("value") == "button1") {                     alert("First Button is pressed - Form will submit")         $("#myform").submit();       }       if ($(this).attr("value") == "button2") {         alert("Second button is pressed - Form did not submit")       }     }); }); </script> </head> <body> <form id="myform">   <input type="email" name="email" placeholder="Enter email" /><br>   <button type="submit" value="button1">First Button</button>   <button type="submit" value="button2">Second Button</button> </form> </body> </html>
Updated on: 2020-06-20T07:14:15+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements