PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

On AJAX submit - external javascript calls die?

  1. tobaccordshow
    Member

    I've got a very simple jQuery call to toggle a class of active on submit button click:

    $('#submit_button').bind('click',function() {
    $(this).toggleClass('active');
    }

    It works great on the initial click. Then the js call does not occur afterwards. Is there anything I need to do to override GF js calls?

    Posted 13 years ago on Monday April 18, 2011 | Permalink
  2. Shouldn't the initial click of the submit button be all that is necessary for the action since that click submits the form anyway? What do you mean it works great on the initial click but not afterwards? Are you referring to a multi-page form?

    Posted 13 years ago on Monday April 18, 2011 | Permalink
  3. tobaccordshow
    Member

    No, not a multi page form.

    If the AJAX form returns with errors, there's the opportunity to, of course, click again and submit. That's where the JS dies.

    Small update to my script: I have two binds now on the jQuery onmouseclick and onmouseup. It's to give that illusion that you pressed and released the button. It works great on the first click (and then you see the AJAX spinner appear). After it returns with errors, the JS never triggers again. No errors. Just doesn't trigger.

    Posted 13 years ago on Monday April 18, 2011 | Permalink
  4. tobaccordshow
    Member

    I would show you the site, but it's password protected. Email me at the address I registered with and I'll give you credentials so you can see it work.

    Posted 13 years ago on Monday April 18, 2011 | Permalink
  5. What's happening is that when the form is reloaded via AJAX, the previous submit button is replaced by a new submit button in the DOM and your javascript is not bound to this new object. To bind your javascript to the submit button with every AJAX form load use this GF jquery event:

    http://www.gravityhelp.com/documentation/page/Gform_page_loaded

    Posted 13 years ago on Monday April 18, 2011 | Permalink
  6. tobaccordshow
    Member

    Worked like a charm. Thanks for this!

    Posted 13 years ago on Tuesday April 19, 2011 | Permalink

This topic has been resolved and has been closed to new replies.