How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Submit a Form Using jQuery
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Submit a Form Using jQuery
Web Development

How to Submit a Form Using jQuery

how7o
By how7o
Last updated: May 23, 2026
4 Min Read
Submit a form with jQuery
SHARE

To submit a form with jQuery, call $('#myForm').submit() from your button handler. That fires the form’s normal submit event. .trigger('submit') is the equivalent longer form. For HTML5-validated submits (respecting required, type="email", etc.), call the native form.requestSubmit() instead.

Contents
  • Submit from a button click
  • Bootstrap modal “are you sure?” pattern
  • Submit with HTML5 validation
  • Submit via AJAX instead
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 with jQuery 3.7. Originally published 2022-07-13, rewritten and updated 2026-05-17.

Submit from a button click

$('#some-button').on('click', function () {
    $('#some-form').submit();
});

// Equivalent
$('#some-button').on('click', function () {
    $('#some-form').trigger('submit');
});

Useful when the submit trigger isn’t a type="submit" button inside the form — like a button in a Bootstrap modal confirming a destructive action.

Submit form with jQuery — .submit(), .trigger('submit'), requestSubmit() with validation, AJAX with preventDefault

Bootstrap modal “are you sure?” pattern

<form id="delete-form" method="POST" action="/items/42">
    <button type="button" data-bs-toggle="modal" data-bs-target="#confirmModal">
        Delete
    </button>
</form>

<div class="modal fade" id="confirmModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">Are you sure?</div>
            <div class="modal-footer">
                <button type="button" class="btn" data-bs-dismiss="modal">Close</button>
                <button type="button" class="btn btn-danger" id="confirm-delete">
                    Save Changes
                </button>
            </div>
        </div>
    </div>
</div>

<script>
$('#confirm-delete').on('click', function () {
    $('#delete-form').submit();
});
</script>

The “Save Changes” button in the modal lives outside the form. Clicking it programmatically submits the form. The opening Delete button uses Bootstrap’s data attributes to show the modal — no JavaScript for that step.

Submit with HTML5 validation

document.getElementById('some-form').requestSubmit();

requestSubmit() (native, supported in every modern browser) runs HTML5 form validation first — required, pattern, type="email", etc. — and only submits if everything passes. jQuery’s .submit() bypasses validation, which is almost never what you want for user-driven submits.

Submit via AJAX instead

$('#myForm').on('submit', function (e) {
    e.preventDefault();

    $.post('/api/save', $(this).serialize())
        .done(function (data) {
            // success path
        })
        .fail(function () {
            // error path
        });
});

e.preventDefault() stops the browser’s normal submit. .serialize() URL-encodes the form’s fields into a query string ready for the request body. The page stays put while the server processes the data.

Frequently asked questions

Why does my $('form').submit() trigger an infinite loop?

If you bound a submit handler that itself calls .submit(), the second call fires the same handler, which fires the second call again. Solutions: (1) bind the handler to a button click, not to the form’s submit event; (2) inside the submit handler, set a flag (form.dataset.submitting = '1') and skip the recursion; (3) use the native form.requestSubmit() which respects HTML validation and runs the normal submit flow once.

Should I use .submit() or .trigger('submit')?

Functionally identical — both fire the form’s submit event. .trigger('submit') is the more explicit name (it’s the same general API as .trigger('click'), .trigger('change')). .submit() with no arguments is the jQuery shorthand. Either is fine; pick by codebase consistency.

How do I include HTML5 validation in the submit?

Use the native form.requestSubmit() (no jQuery, no library). It runs HTML5 form validation first (required, pattern, type="email") and only submits if everything passes. Plain .submit() (jQuery or native) skips validation, which is rarely what you want for user-driven submits.

How do I prevent the default submit and submit via AJAX instead?

Bind to the submit event on the form, call e.preventDefault(), then send the form data via fetch/jQuery AJAX: $('#myForm').on('submit', function (e) { e.preventDefault(); $.post('/api', $(this).serialize()); }). .serialize() turns the form into a URL-encoded query string ready for the request body.

Related guides

  • How to Check if a Bootstrap Modal Is Open with jQuery
  • How to Add a Required Attribute to Input Fields in jQuery
  • How to Disable or Enable an Input with JavaScript or jQuery

References

jQuery .submit(): api.jquery.com/submit. MDN HTMLFormElement.requestSubmit(): developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit. jQuery .serialize(): api.jquery.com/serialize.

TAGGED:formsJavaScriptjQuery

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Store a PHP array in a MySQL database with JSON How to Store a PHP Array in a MySQL Database
Next Article Trigger a function when DataTables loads data via Ajax How to Trigger a Function When DataTables Loads Data
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

MySQL remove string from column — REPLACE and REGEXP_REPLACE patterns
Web Development

How to Remove a Specific String from a Column in MySQL

6 Min Read
Prevent tab key from focusing on a link with tabindex=-1
Web Development

How to Skip a Link When Pressing Tab (tabindex=-1)

5 Min Read
Reload DataTables with a new Ajax URL
Web Development

How to Reload DataTables with a New Ajax URL

4 Min Read
Fix MySQL CONCAT returning NULL with COALESCE or CONCAT_WS
Web Development

How to Handle MySQL CONCAT Returning NULL

4 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?