Field validation and focus

Hi to all,
I posted already this question in the general category, but it’s probably not correct.
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’ => “WARNING”,
‘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’ => “WARNING”,
‘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?
Another forum member has suggested:

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.

But in this way I go into an infinite loop with the alert.
Thank You and Best Regards