How to submit a form using jQuery click event?

jQueryWeb DevelopmentFront End Technology

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>
raja
Published on 20-Dec-2017 15:23:18
Advertisements