Q:

how to define functions in jquery?

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;
});

A:

or you could use use regular function syntax
function do_on_blur(){
   // your base. I'm in it
}

and 
$("#join_username").blur( do_on_blur );

A:

Simply define a function instead of passing the blur() an anonymous function:
$.myFunctionName = function()
{
   // your code here
}

$("#join_username").blur($.myFunctionName);

If you want the function to be called in response to an event (such as document.ready), just call it like you would a normal function.
$(document).ready(function()
{
    // -- define your function
    $.myFunctionName = function()
    {
       //your code here
    }

    // -- add a callback to blur on an input
    $("#join_username").blur($.myFunctionName);

    // -- manually call the function once
    $.myFunctionName(); 
});

