Combining 2 Javascript/Jquery scripts
<p>Im having a issue, I need to combine 2 scripts together. One of which is a validation and the other is variables/ajax script. I tried but i cannot get it to work. I put it within the script under the area that checks if it has the needfilled element attached however it submits without executing the ajax call.</p>

<p>Script 1:</p>

<pre><code>$(document).ready(function(){
 $("#loading").hide();

// Place ID's of all required fields here.
required = ["parentFirstName", "parentLastName", "parentEmailOne", "parentZip"];
// If using an ID other than #email or #error then replace it here
email = $("#parentEmailOne");

errornotice = $("#error");
// The text to show up within a field when it is incorrect
emptyerror = "Please fill out this field.";
emailerror = "Please enter a valid e-mail.";




$("#theform").submit(function(){    
    //Validate required fields


    for (i=0;i&lt;required.length;i++) {
        var input = $('#'+required[i]);
        if ((input.val() == "") || (input.val() == emptyerror)) {
            input.addClass("needsfilled");
            input.val(emptyerror);
            errornotice.fadeIn(750);
        } else {
            input.removeClass("needsfilled");


        }
    }
    // Validate the e-mail.
    if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
        email.addClass("needsfilled");
        email.val(emailerror);
    }

    //if any inputs on the page have the class 'needsfilled' the form will not submit
    if ($(":input").hasClass("needsfilled")) {
        return false;
    } else {
        errornotice.hide(); 
        return true;
    }
});


// Clears any fields in the form when the user clicks on them
$(":input").focus(function(){       
   if ($(this).hasClass("needsfilled") ) {
        $(this).val("");
        $(this).removeClass("needsfilled");
   }


});
}); 
</code></pre>

<p>Script 2:</p>

<pre><code>// Form Varables
var parentFirstNameVal = $("#parentFirstName").val();
var parentLastNameVal = $("#parentLastName").val();
var emailaddressVal = $("#parentEmailOne").val();
var parentPhoneVal = $("#parentPhone").val();
var parentAddressVal = $("#parentAddress").val();
var parentAddressContVal = $("#parentAddressCont").val();
var parentCityVal = $("#parentCity").val();
var parentStateVal = $("#parentState").val();
var parentZipVal = $("#parentZip").val();   
var parentListenVal = $("#parentListen").val();     
var codeVal = $("#code").val();     
var getUpdateVal = $("#getUpdate").val();       

            input.removeClass("needsfilled");
            $("#message-space").html('&lt;br /&gt;&lt;br /&gt;&lt;span class="greenText"&gt;Connected to Facebook.&lt;/span&gt;&lt;br /&gt;');
            $("#loading").show();


            var counter = 0,
                divs = $('#div1, #div2, #div3, #div4');

            function showDiv () {
                divs.hide() 
                    .filter(function (index) { return index == counter % 3; }) 
                    .show('fast'); 

                counter++;
            }; 

            showDiv();

            setInterval(function () {
                showDiv();
            }, 10 * 600); 

            alert(parentFirstNameVal);

            $.ajax({
                type: "POST",
                url: "includes/programs/updateEmailsTwo.php",
                data: "parentFirstName="+parentFirstNameVal+"&amp;parentLastName="+parentLastNameVal+"&amp;UserEmail="+emailaddressVal+"&amp;parentPhone="+parentPhoneVal+"&amp;parentAddress="+parentAddressVal+"&amp;parentAddressCont="+parentAddressContVal+"&amp;parentCity="+parentCityVal+"&amp;parentState="+parentStateVal+"&amp;parentZip="+parentZipVal+"&amp;parentListen="+parentListenVal+"&amp;code="+codeVal+"&amp;getUpdate="+getUpdateVal+"&amp;ref=&lt;?php echo $_SESSION["refid"]; ?&gt;",
                success: function(data){
                $("#message-space").html('&lt;br /&gt;&lt;br /&gt;&lt;span class="greenText"&gt;Complete&lt;/span&gt;&lt;br /&gt;');
                divs.hide() 

        }
     });
</code></pre>
