Hi i'm currently using the dialog functionality (modal form) from UI
library to submit data to the database.  All the validation checks
have been running ok until one of the validation checks requires a
ajax call to check if a username exsist in the database.  I'm fairly
new to both javascript and jquery so this could be a fairly basic
blunder.  Initially, i thought it was an sycronicity problem, but I
changed the $.ajax async option to true but still no joy, so maybe it
something to do with scope etc?  Here's the code and thanks for any
help in advance.

function checkIfUsername()
{
        $.ajax({
                type: "POST",
                url: ""+CI_ROOT+"index.php/admin/check_if_username",
                data: ({username: username.val()}),
                async: false,
                dataType: "json",
                success: function(data){
                        returnUsernameBool(username, data);
                }
        });
}

function returnUsernameBool(o, data)
{
        if(data.bool == true){
                o.addClass('ui-state-error');
                updateTips("Your username must be unique");
                alert('false'); //this works
                return false; //still can't return bool
        }
        else{
                alert('true'); //this works
                return true; //still can't return bool
        }
}

bValid = bValid && checkIfUsername(username);
alert(bValid); //still gives undefined

Reply via email to