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
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026

You Might Also Like

Make the first option selected in a jQuery select
Web Development

How to Make the First Option Selected in a with jQuery

4 Min Read
Upload files via Ajax with jQuery using FormData
Web Development

How to Upload Files via Ajax with jQuery

4 Min Read
Fix Laravel CSRF token mismatch in DataTables Ajax
Web Development

How to Fix Laravel CSRF Token Mismatch in DataTables Ajax

4 Min Read
JavaScript format number with decimals — toFixed, Math.floor, and Intl.NumberFormat
Web Development

How to Format a Number with Decimals in JavaScript

5 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?