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

  • Home
  • SEARCH
  • 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 6868795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:28:41+00:00 2026-05-27T03:28:41+00:00

Having problem with jquery submit(). The problem is that it doesn’t work on the

  • 0

Having problem with jquery submit(). The problem is that it doesn’t work on the site, it sends me to the action url (as im using get) instead of preventing it and running the function inside the submit(). It works if add the submit()-script in the console. How come?

This is my js file:

$(function(ready){
  $('#contact-form button')
    .removeClass('disabled')
    .removeAttr('disabled');

  $('#contact-form').submit(function(e){
    alert('????????????????????????????');
    return false;
      e.preventDefault();

      $this = $(this);
      $this.addClass('disabled').attr('disabled', true);
      $('#contact-form img').addClass('showLoader');

      $.post('theme/widgets/contact-form/ajax/send-mail.php', $('#contact-form').serialize(), function(d){
        $this.removeClass('disabled').removeAttr('disabled');
        $('#contact-form img').removeClass('showLoader');

        try {
          $msg = $.parseJSON(d);
        } catch (e) {
          console.log(e, d);
          $msg.error = true;
          $msg.message = "Unknown error occoured. See console for more information.";
        }

        if (!$msg.error) {
          $('#contact-form input').val('');
          $('#contact-form textarea').val('');
        }

        alert($msg.message);
      });
  });
});

And this is my form:

$html = "<form id='contact-form'>
  <label>".__('name', false, $ld)."</label>
  <input type='text' name='name' /><br />
  <label>".__('email', false, $ld)."</label>
  <input type='text' name='email' /><br />
  <label>".__('body', false, $ld)."</label>
  <textarea name='body'></textarea><br />
  <img src='".THEME."images/ajax-loader-small.gif' />
  <button class='disabled' disabled='disabled'><span>".__('send', false, $ld)."</span></button>
</form>";

How come the jquery submit only reacts if i paste it into the console and not when the page loads? I am not getting any javascript errors and have tried with a lot of different jquery versions.

  • 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-27T03:28:42+00:00Added an answer on May 27, 2026 at 3:28 am

    The problem is that the event is not firing. The code, you said, executes fine… after you fire the event manually. The events could not be firing for a few reasons… the first is usually because the events are wired up before the html is rendered. You could solve this by using delegates, but I believe (after ‘solving’ the problem) that your event is not firing because the event you are wiring is on form submission but you do not have a submit button on your form. You may want to try making the button a submit button, or making the code fire on the button click instead of the form submit.

    Here’s the code for using delegates

    $("body").delegate("#contact-form", "submit", function() {
        alert('????????????????????????????');
        return false;
          e.preventDefault();
    
          $this = $(this);
          $this.addClass('disabled').attr('disabled', true);
          $('#contact-form img').addClass('showLoader');
    
          $.post('theme/widgets/contact-form/ajax/send-mail.php', $('#contact-form').serialize(), function(d){
            $this.removeClass('disabled').removeAttr('disabled');
            $('#contact-form img').removeClass('showLoader');
    
            try {
              $msg = $.parseJSON(d);
            } catch (e) {
              console.log(e, d);
              $msg.error = true;
              $msg.message = "Unknown error occoured. See console for more information.";
            }
    
            if (!$msg.error) {
              $('#contact-form input').val('');
              $('#contact-form textarea').val('');
            }
    
            alert($msg.message);
          });
    });
    

    jQuery 1.7 call (recommended, delegates are much more efficient in 1.7 than older versions):

    $("body").on("submit", "#contact-form", function() {
      //code here
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problem getting my tooltip to work when using the jQuery load()
I'm having a little problem with jQuery: I'm having .submit() defined on a form,
I am having two problems. First: Trying to submit this form using jquery. When
I am using the excellent jQuery MultiSelect plugin. The problem I have is that
I am having a very specific problem in JQuery The code below is used
I am having a problem trying to use the prependTo() function in jQuery... for
I'm having a problem trying to format the output on the jQuery UI datepicker.
I am using the jQuery UI components but having some problems. If I try
I'm having a really irritating problem doing something that I'm sure I've done before.
I'm having a little problem with form submission with jquery. I've submitted a lot

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.