Usually, the form is sent when the user presses the submit button. However, in some cases, you may need to submit the form formally using JavaScript. JavaScript provides a form factor that contains the submit () method. Use the form 'id' to find the form object.


<!DOCTYPE html>
        <p>Enter data and submit the form.</p>
        <form id="myForm" action="post.php">
            First name: <input type="text" name="fname" class="form-control"><br>
            Last name: <input type="text" name="lname" class="form-control"><br><br>
            <input type="button" onclick="submitForm()" value="Submit form">

            function submitForm() {


Run the following code and see the results