Infinite alert with . Focus()

Asked

Viewed 56 times

0

Why it keeps giving Infinite Time when I try Focus() in an incorrectly filled onblur field?

if(ret = TstForDat(wCampo, "")!=""){
          alert('Data Incorreta! Favor preencher a data corretamente.');
          wCampo.focus(); //apos colocar isto, o alert em cima fica aparecendo sem parar.
}
  • 5

    Probably because the event Blur is fired when setting new focus.

  • I managed to resolve... I set the correct date before setting Focus(). Thanks Anderson!

1 answer

0

This is because the event associated with Onblur generates an Alert and a Focus, and, in turn, the Focus event triggers the Onblur again.

I solved this problem by performing a work-Around:

    if(ret = TstForDat(wCampo, "")!=""){
          alert('Data Incorreta! Favor preencher a data corretamente.');
          wCampo.Value = '';
          wCampo.select();
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.