JQuery focus () function starts again when blur ()

Say I have an input field "lastname", but I do not want people to insert something if the field "firstname" is still empty. Example: http://jsfiddle.net/GQyHp/

$('input[name=lastname]').focus(function() {
  if (!$('input[name=firstname]').val()) {
    alert('First enter your first name');
    $(this).blur();
  }
});

If I click on the "lastname" field, I will get a popup, but after I click "OK", it will launch this popup again. If I delete blur(), there is no second popup.

How can I prevent this function from starting with a function blur()?

+3
source share
1 answer

I think the problem is with alert ().

, , . . http://jsfiddle.net/GQyHp/1/, patrick, , .

, , , , , .

+2

Source: https://habr.com/ru/post/1763271/


All Articles