Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
<!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>Advertisements