I need to replicate a certain function which is present in PowerBuilder.

I need to replicate a certain function which is present in PowerBuilder.

In Powerbuilder there is a functionality, that upon validation of a control say a textbox, if it returns an error, it refocuses on the control, and keep's the focus there (ie in case user clicks outside again, due to the wrong value in textbox, it raises the alert again and refocuses back on itself, till the value in textbox is corrected).

I initially tried to do this with onchange, I got the alert to fire based on the condition, and refocus back on the control, but it works only once (i supposes because the onchange event has aldready fired once aldready). I need this to be persistent till the user changes the value in the textbox to satisfy the validation condition.

What would be the optimal way to do this? I will need to apply this to multiple controls , if possible can it be extended somehow?