• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] don't understand javascript variable scope; now talking about validation plugin

#1
[eluser]SPeed_FANat1c[/eluser]
Code:
function name_free(value, element){    //validation rule
    var result;
    if($('input[name="name"]').val() != value)
    {
        //console.log($('input[name="name"]').val());
        $.post(CI.base_url + "admin_/info_psl/name_check_ajax", { pavadinimas: value}, function(data){    
            //console.log(data);
            if(data == 'true')
                result = true;
            else result = false;
         });
    }
    else result = true;    //jei vienodi tai viskas ok
    console.log(result);
    return result;
}

when
Code:
if($('input[name="name"]').val() != value)
is true

result is not set, it is undefined. It is outside the callback funciton, so why it is not set? How do I set it?


Messages In This Thread
[solved] don't understand javascript variable scope; now talking about validation plugin - by El Forum - 01-25-2011, 04:55 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.