Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8681799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:36:11+00:00 2026-06-12T21:36:11+00:00

submitting form with jQuery works $(‘#testform’).submit(); doesn’t work $(‘#testform’).submit(function () { alert(‘test1’); return true;

  • 0

submitting form with jQuery

works

         $('#testform').submit();

doesn’t work

              $('#testform').submit(function () {
                 alert('test1');
                return true;
              });

This is just an exmaple but at times i’d like to do stuff before submission of the form. Like for example submit the form using $.POST

Update:

If I keep both then the $.POST has no value because the form still gets submitted the traditional way, without ajax…

                    $("#testform").submit(function() {
                            $.post('/myajaxcontroller', function(data) {
                                $('#result').html(data);
                            });
                    });
                    $("#testform").submit();   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:36:12+00:00Added an answer on June 12, 2026 at 9:36 pm

    The first example submits the form. The second example sets an event handler for when you submit the form. You need both;

    If you need to to something asynchronous, you’re forced to return false from the submit handler so the form doesn’t get submitted, and you can submit the form in the AJAX callback.

     // Send an AJAX request before submitting the form
     $('#testform').submit(function () {
         var form = this;
         $.post('/myajaxcontroller', function(data) {
             $('#result').html(data);
             // everything is good, submit the form on our own
             if (data.looksGood) {
                 form.submit();
             }
         });
    
         return false;
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm loading form into jquery-ui dialog using jquery.html() function and then Submitting doesn't work
I'm submitting a form using a call to this JavaScript function: function emailFriend(){ jQuery(form[name='comparisons']).attr(action,
I faced the following issue while I submitting my form using jQuery FORM and
I have formatted my form using uniform jquery plugin. Also for submitting the form
I am having difficulty using JQuery UI Modal Dialog when submitting a form. The
I am getting Error in submitting the form using AJAX and Jquery, following is
I'm submitting an html form to a mySQL db with jQuery .ajax. When I
i try to validate the form before submitting the request. i am using jquery
I have written a few jquery functions for form validation. It works fine but
i'm using ajax contact form, downloaded from: http://youhack.me/2010/07/22/create-a-fancy-contact-form-with-css-3-and-jquery/ Everything works ok except UTF as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.