title: How to convert asynchronous call to synchronous in javascript?
body: <p>I am using javascript in client side and node.js in server side, Actually i have tried to make a remote validation for input fields, result must be boolean and it should be based on the server call, My code as follows,</p>
  
  <pre><code> jQuery.validator.addMethod("remoteValidation", function(value, element) {
  
      var accountName = $("#accountName").val();
      var accountType = $("#accountType").val();
      var valid = this.Validation(accountType,accountName);
     //returning undefined becoz return statement executing before server side execution
      return valid;
  
  }, "Entered email or username already exists");
  
   this.validation = function(accountType,accountName,cb){
      var valid =null;
    ss.rpc('AccountsManagement.userNameChecker',accountType,accountName,function(res) {
              // res will return boolean
          valid = res;
      });
              //valid is null becoz this line is executing before valid = res line.
      return valid;
  };
  </code></pre>
  
  <p>my server side code:</p>
  
  <pre><code>   services.imAccountsService.getAllImAccounts(accountType,accountName,
     function(err,result){
      if(err){
      return;
      }
      if(result == null){
         res(true);
      }
      else{
         res(false);
      }
  
     });
  </code></pre>
  
  <p>My problem is async execution, how to make code synschronous in this situation..</p>