I've the code below that works great in my ready function in jquery, when i fill the form and change focus from the input element to another run the ajax check and assign a css class to the element, showing if is validated or not. everything ok.
id' like to define with this code a function so i can call it also when the page is just loaded, so the check will be performed also if the form is populated in server side, and on blur, but i faced troubles defining functions in jquery.
this is the code that runs on blur
$('#join_username').blur(function(){
$('#join_username').addClass(\"join_form_input_checking\");
$('#join_username').removeClass(\"join_form_input\");
$('#join_username').removeClass(\"join_form_input_error\");
$('#join_username').removeClass(\"join_form_input_verified\");
$.post(\"inc/viewlets/join_form/check_username.php\", {
join_username: $('#join_username').val()
},
function(response){
setTimeout(\"finishAjaxUsername('usernameResult', '\"+escape(response)+\"')\", 400);
if(escape(response)=='true') joinFormCheck[0]=true;
else joinFormCheck[0]=false;
checkFormArray(joinFormCheck);
}
);
return false;
});