Jquery problem with a function with a post inside a submit form

Jquery problem with a function with a post inside a submit form

Hello

I have this code, the problem is this, when click submit button, execute submit function, when arrives to 
validateEmail enters in the function, and before get $.post result , the function return true. I stop the process with return false in the form submit, and with alert command I check that this is the process:

First enters in validateEmail, the return true and finally $.post return result (this works right). I do not understand why when enters in function validateEmail, first go to $.post and then waits until ajax return result ( I repeat, this works fine), and then and only then goes on in the function.

  1. jQuery(document).ready(function(jQuery) { jQuery('#myform').submit(function(){ result = true; //check differents fields var telephone = jQuery('#telephone').val(); if(telephone!=''){ result = false; //message } //Now I check for the email, BEFORE everything was fine. var email = jQuery('#email').val(); if(email!=''){ result = validateEmail(JQuery('#email')); //any message } return result; }); function validateEmail(email){ var value = email.val(); jQuery.post('index.php?option=com_mycomponent&format=raw', {email:value}, function(data){ if(data=='error'){ return false; } } }); //the function arrives here, before JQuery.post returns a value
                      // I check that Jquery,post works fine.
     return true; }