Q:

How to Submit a Form Using jQuery

0

How to Submit a Form Using jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the jQuery submit() Method

You can use the submit() method to submit an HTML form (i.e. <form>) using jQuery.

The jQuery code in the following example will submit the form on click of the button (i.e. the <button> element) which has the type attribute set to button (i.e. type="button").

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Form Submit</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function(){
    $("#submitBtn").click(function(){        
        $("#myForm").submit(); // Submit the form
    });
});
</script>
</head>
<body>
    <form action="action.php" method="post" id="myForm">
        <label>First Name:</label>
        <input type="text" name="first-name">
        <button type="button" id="submitBtn">Submit Form</button>
    </form>
</body>
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Create a DIV Element in jQuery... >>
<< How to Check If an Array Includes an Object in Jav...