Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why will focusout(); in jQuery not perform a function after focusing out of a field?

I am trying to use the focusout(http://api.jquery.com/focusout/) function in jQuery, to perform a function after the user focus away from an input form field, but it's not working.

Here is my code:

$("#employee_id").focusout(function(){
  var employeeId = $("#employee_id").val();
  if(employeeId == '') {
    $("#employee_id").after('<div class="error">Your employee id number is required.</div>');
    hasError = true;
  }
});

I am using jquery-1.3.2.min.js since another plugin I am using(qtip) is giving me an error when I try to use jquery-1.4.2.min.js.

How can I make the focusout event work, or is there another way to do what I am trying to accomplish?

like image 793
zeckdude Avatar asked Jan 23 '23 11:01

zeckdude


1 Answers

Since you just seem to care about that field and not the parent/bubbling, use .blur():

$("#employee_id").blur(function(){
  if($(this).val() == '') {
    $(this).after('<div class="error">Your employee id number is required.</div>');
    hasError = true;
  }
});
like image 159
Nick Craver Avatar answered Jan 25 '23 02:01

Nick Craver