I may have titled this wrong but that is the best description I could think of being a newbie.
I have a function the inside calls another function. What I need to have happen is for the calling function to wait for a response from the called function but that is not what is happening. The calling function goes right on processing the rest of the script which of course errors out because the required vars are not set properly yet. Here is some code.... var chkmail = function(data){ if (data.exists == 1){ $('#emailerror').show(); var emailerror = 1; } else{ $('#emailerror').hide(); var olde = $('#editaemail').val(); var emailerror = 0; } return emailerror; } //This is the pre submit function for the Jquery form plugin function presub(){ \\get the new email address entered in the form newe = $('#editaemail').val(); \\set the url var so IE won't cache the ajax call url = '/myaccount/process.cfm?t=' + new Date().getTime(); \\password change test vars p1 = $('#editapassword1').val(); p2 = $('#editapassword2').val(); \\default error state vars set to 0 emailerror = 0; passworderror = 0; \\UI update to notify client $('#editasave').attr("disabled","disabled").attr("value","One Moment"); \\Test old email (set at doc.ready) to new email to see if they are different if(olde != newe){ \\send new email through post to search DB for existing \\returns JSON either {"exists":"1"} or {"exists":"0"} \\callback set to fire chkmail() $.post(url, {checkname: newe}, chkmail, "json"); } \\Check password fields to see if they are the same if (p1 != p2){ $('#passerror').show(); passworderror = 1; } else{ $('#passerror').hide(); } if(emailerror == 0 && passworderror == 0) { return true; } else{ $('#editasave').removeAttr("disabled").attr("value","Save Changes"); return false; } } After the $.post functions callback is triggered the script continues on to the password checks and since the $.post function hasn't received a response yet, the system doesn't catch the errors with the email address. I'm sure there is a more robust way of doing this but as I said earlier, I am a newbie to JS and learning as I go. Any help would be appreciated.