Problem with focus on a field

Hi to all,
I want to validate a field immediately when it loses focus by moving to another field.
That’s why I created an ajax onBlur event.
If the field is invalid, a sweet alarm is displayed.
So far everything works well.
However, I want to make the focus return to the invalid field; I tried to create a javascript method but it doesn’t work; the focus always goes to the next field.
For instance, suppose the field is called fld_login and I want to check that it is not already assigned to another user or empty, I wrote this code for the ajax event fld_login_onBlur

$login={fld_login};
$sql_command =
    "select fld_login from tb_users where fld_login = '{fld_login}'";
    sc_lookup(ds_user, $sql_command);
if ({ds_user} != false)
    {
        $params = array(
        'title' => "Attenzione",
        'type' => "error",
        'width' => '350px',
        'confirmButtonText' => 'OK');
        $desc="The entered login: ".$login." "."already in use";
        sc_alert($desc, $params);
        sc_ajax_javascript('focus_login');
        }  else {
           $params = array(
        'title' => "Attenzione",
        'type' => "error",
        'width' => '350px',
        'confirmButtonText' => 'OK');
        $desc="This field cannot be empty!";
        sc_alert($desc, $params);
        sc_ajax_javascript('focus_login');
}

and I wrote this simple code for the javascript method focus_login

$('#id_sc_field_fld_login').focus();

Everything works well; the field is validated and if an error occurs the appropriate alarm is displayed.
But javascript doesn’t work and focus goes to the next field.
Do you have any ideas that can help me?
Thank You and Best Regards

What about triggering your code on the next field instead ?
Instead of checking onblur on field A (fld_login) try to check on event onfocus on field B.

Thank You for reply.
What advantage would I have?
Also, if I delete the onBlur event on field A and create the onFocus event on field B, I go into an infinite loop with the alert.