Hi all!

I'm adding a userCheck method to the validation plugin. It checks if
the username i available, and if not an error message diplays, its
done with ajax, my script does not work properly. I'm pretty new to
javascript and jquery so maybe its an easy problem...

its done with ajax and if the user exists i get a response with the
username, if the user dont exist i get nothing back. The problem is
that if i fill in the userfield with a name that doesnt exist and i
change field (blur), the error message displays. And if i go back and
type in the userfield the errormessage is still there until i change
fields again. and it seems like the keyup event is on letter behind
all the time, so if i type in an existing username i hav to type one
more letter to get the error message!! Does anyone know whats going on
and do i have to declare a global variable for this?

var sUserResult;

$.validator.addMethod('userCheck', function (value) {
        $.ajax({
            type: "POST",
            url: "_scripts/send_message.php",
            data: "action=checkuser& user=" + value,
            success: function(msg){
                if (msg) {
                    sUserResult = false;
                }
                else {
                    sUserResult = true;
                }
            }
        });
     return sUserResult;
});

Many thanks in advance

George

Reply via email to