Frm PHP to Javascript

When In a PHP form I fill a field, an onBlur event validates this field and if an error occurs the my_alert function is displayed.
This is the part of the code that runs my_alert function.

$params = array(
‘title’ => “Attenzione”,
‘type’ => “error”,
‘width’ => ‘350px’,
‘confirmButtonText’ => ‘OK’);
$desc=“The field cannot be empty”;
my_alert($desc, $params);

So far everything is ok; the my_alert function work fine.
But I wish that, when the alert window is closed, the focus remain on the invalid field and to do this I created a simple javascript function that contains a single line of code and exactly $(’#field_id’). Focus () and that should be done immediately after my_alert.
The problem is that it doesn’t work: the focus always goes to the next field.
However, if I remove my_alert, this does not happen.
They suggested me to try to pass $params and $desc directly to the javascript focus function and also run my_alert inside it, but I’m in trouble because I don’t know javascript well.
Can someone help me?
Thank You and Best Regards

Please add a link or file… there are to many reasons and form handlers.

In addition to what @MaxZieb asked, is this related to a Hype document?