email.onblur = function() { validate_data('email',$('#email').val(),0); $('#email').mailgun_validator({ api_key: 'key', in_progress: validation_in_progress, // called when request is made to validator success: validation_success, // called when validator has returned error: validation_error, // called when an error reaching the validator has occured }); }; 

there is such a code for checking email, the first function is user, the second is anonymous from the library. In this case, email is the input id. An example is taken from here: link1 The problem is that when you remove the focus for the first time, only the first function is triggered, when you do everything again, two functions are worked out. What is the problem?
UPD full call code: just wrapped in $(document).ready(function () { }); Used library mailgun, jquery plugin. Documentation here link

  • onblur absolutely nothing to do with. probably you do it somewhere in modalke, and modal ayaksom tightens ..... you need to do unbind events .... you need to look at the whole code, including it happens in add. window or not - Alexey Shimansky
  • call, + code in which this block with email.blur is located .... I assume that it is in some block a la $("selector").click(function(){ - Alexey Shimansky
  • mailgun_validator is an asynchronous function, just does not have time to return the answer right away - Grundy
  • Without indicating what kind of library is used it is difficult to say. cost to add a minimal reproducible example. Perhaps the first call does not validate, but initializes the object. Even the most likely. - Grundy
  • If the code is wrapped only in $(document).ready(function () { }); where does email come from? - Alexey Shimansky

1 answer 1

You confused the initialization of the validator and its call.

Take out the validator initialization call

 $('#email').mailgun_validator({ api_key: 'key', in_progress: validation_in_progress, // called when request is made to validator success: validation_success, // called when validator has returned error: validation_error, // called when an error reaching the validator has occured }); 

from the blur handler.

  • if I understand you correctly, then initialization does not occur in blur, but is the call to the user function just inside? - VK
  • @ Vadim.K, yes, I suspect that the library hangs all the handlers by itself, so it is enough just to call for initialization, it will do the rest itself. While the custom function is a regular function that simply checks the value - Grundy