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 7498813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:36:19+00:00 2026-05-29T19:36:19+00:00

I want to submit a form using submit(), and indeed it works fine when

  • 0

I want to submit a form using submit(), and indeed it works fine when I only use submit() without any anonymous function inside, the problem is when I use the anonymous function like this then it stops working

$('form').submit(function() {
    alert("alert never shows up :( ");
});

This is my code: (sorry for mixing jQuery and getElementsByTagName, old guy’s fault)

var uform = $('#createItem1');
if(uform[0]) {
    // UI's first validation image extension before server-side
    var _validFileExtensions = [".jpg", ".jpeg", ".gif", ".png"];
    var arrInputs = uform[0].getElementsByTagName("input");
    for (var i = 0; i < arrInputs.length; i++) {
        var oInput = arrInputs[i];
        //Checks if image is of valid extension
        if (oInput.type == "file"){
            var sFileName = oInput.value;
            if (sFileName.length > 0) {
                var blnValid = false;
                for (var j = 0; j < _validFileExtensions.length; j++) {
                    var sCurExtension = _validFileExtensions[j];
                    if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
                        blnValid = true;
                        // this works fine
                        $('#createItem1').submit();
                        break;
                    }
                }

                if (!blnValid) {
                    alert("Sorry, " + sFileName + " is invalid, allowed extensions are: " + _validFileExtensions.join(", "));
                    $('a#linkStep1').trigger('click');
                    return false;
                }
            }
        }
    }
}
return false;

Again, as soon as I try to replace current submit() for something like this, it stops working

$('#createItem1').submit(function() {
   alert("something");
});

Any idea why is not working?

  • 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-05-29T19:36:20+00:00Added an answer on May 29, 2026 at 7:36 pm

    If you pass a function (anonymous or otherwise) to the .submit() method that defines a handler that will be run when the form gets submitted, but it doesn’t actually cause the form to submit. If you pass no parameters to .submit() that makes it submit.

    If you want to define a handler and submit at the same time you can do this:

    $('#createItem1').submit(function() {
       alert("something");
    }).submit();
    

    .submit() with no parameters is a shortcut for .trigger("submit").

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to submit a form without using submit button how can i do
When I submit form using button it works fine (renders PartialView in the menuload
I would like to use jQuery.ajax to submit a form using POST without having
I am using html, javascript & mod_python. I want to submit html form. To
I want to submit a form using jQuery in a CodeIgniter application. However, the
I'd like to submit a form using GET but without passing the value of
I want to debug a form submit using netbeans but cannot find the option
I want submit form with some parameters using httpunit. I wrote smt like WebForm
Hi I am using php and i want to submit form on onclick event
So what I want to do is to submit a form using jQuery's AJAX

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.