How to submit a form using jQuery click event?


To submit a form using jQuery click event, you need to detect the submit event. Let’s submit a form using click event and without using click event.

Example

You can try to run the following code to learn how to submit a form using jQuery click event −

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(){
    $(function() {
   $('#submit1').click(function(e) {
        e.preventDefault();
        $("#Demo").submit();
    });

   $('#submit2').click(function(e) {
        e.preventDefault();
        $("#Demo").submit();
    });
});
});
</script>

</head>
<body>
<form action="javascript:alert('submitted');" method="post" id="Demo">
    <label>Team</label>
    <input type="text" name="name" value="" />
    <input type="submit" name="submitme" value="Submit" id="submit1" />
    <p><a href="#" id="submit2">Submit</a></p>
</form>
</body>
</html>

Updated on: 17-Feb-2020

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements