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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:57:49+00:00 2026-05-25T23:57:49+00:00

Some beginner help needed if anybody can.. I’m writing a contact form with a

  • 0

Some beginner help needed if anybody can..

I’m writing a contact form with a checkbox to signup to a MailChimp list.

I’m trying to write a JQuery script that checks if the ‘signup’ checkbox is checked then posts the form data to 2 separate PHP scripts – one which posts the data to the MailChimp list and another which sends an email with the forms contents.

How do I:

  1. Check if the checkbox is selected, then if selected:
  2. Post the data to the two scripts – but only display the success after BOTH scripts have completed

Currently the script I have works, but ignores the checkbox and displays the success message even if the first script is still processing.

Here’s what I have (edited for clarity) – I’d like to wrap this in an IF statement and then chain the ajax posts together THEN display eh success message

(Ive just thought: Am I right in saying the success part of the ajax call has no idea if the PHP part completed successfully? It just returns success if it sends the data of the the scripts ok? If I wanted to wait until the PHP scripts returned a success is it best to just put in a time delay to give them chance to run before displaying the success message?)

Many thanks for any help!

//check if signup checkbox is checked
if ($('#signup').is(':checked')){

var callOneSuccess, callTwoSuccess;

$(function(){
  $.ajax({
    type: "POST",
    url: "bin/enquiry_process.php",
    data: 'name=' + name + '&email=' + email + '&phone=' + phone + '&message=' + message + '&signup=' + signup,
    success: function(){
      callOneSuccess = true;
      bothAjaxCallsComplete();
    }
  });

  $.ajax({
    type: "POST",
    url: "bin/addtomailchimp.php",
    data: 'name=' + name + '&email=' + email,
    success: function(){
      callOneSuccess = true;
      bothAjaxCallsComplete();
    }
  });
}

function bothAjaxCallsComplete()
{
  if(callOneSuccess == true && callTwoSuccess == true)
  {
    // fade out loading icon
    $('.loadericon').fadeOut(1000);

    // get height of the the form container then apply it to the css so it doesn't collapse when the form fades out
    var formHeight = $('.form_wrap').height();
    $('.form_wrap').css('height', formHeight + 'px');

    // fadeOut contact form
    $('#contactform').fadeOut('slow', function() {
        //fadeIn success message
        $('#send_success').fadeIn('slow');
    });
  }

}else{
//do something else.        
}
  • 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-25T23:57:49+00:00Added an answer on May 25, 2026 at 11:57 pm

    I believe since you have two asynchronous calls you will need to take a look at the global jquery ajax events.

    one of them triggers when ALL ajax functions have stopped, conveniently named .ajaxStop();

    however just putting your function in there is not going to work out of the box. it does not say your call was successful or not, that is something you would need to workaround.

    another option would be to call a function from both success callbacks

    var callOneSuccess, callTwoSuccess;
    
    $(function(){
      $.ajax({
        type: "POST",
        url: "bin/ajaxOne.php",
        data: myData,
        success: function(){
          callOneSuccess = true;
          bothAjaxCallsComplete();
        }
      });
    
      $.ajax({
        type: "POST",
        url: "bin/ajaxTwo.php",
        data: myData,
        success: function(){
          callOneSuccess = true;
          bothAjaxCallsComplete();
        }
      });
    }
    
    function bothAjaxCallsComplete()
    {
      if(callOneSuccess == true && callTwoSuccess == true)
      {
        //do all your stuff here
      }
    }
    

    both ajax calls are asynchronous, your own third function will just test if both have been successful and the do your stuff… if only 1 call was ready and calls the third function it would not continue because both booleans were not true yet.

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

Sidebar

Related Questions

I have another beginner's question that hopefully someone can help with. I'm trying to
being a regex beginner, I need some help writing a regex. It should match
Can one of you smarties point me to some beginner content for converting an
I'm a beginner C++ programmer, and to stretch my mind I've been trying some
I am just a beginner in C++. I am trying to construct some header
hi im pretty much a beginner.I need some help turning this script in an
Im still a beginner in C programming and I need a little help writing
I have a form field in Drupal which I need some help with. The
I'm no php expert (a mere beginner) but need some help! After hours searching
I am trying to use VIM for some programming. I am a total beginner

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.