How can I defer jQuery.blur function?

I use this code to check the input field, but I do not want it to extract text from the field up to half a second after the field has lost focus. How can i do this?

$(document).ready(function()
    {
    $("#group_id").blur(function()
    {
    $("#gmsgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
            $.post("group_availability.php",{ group_id:$(this).val() } ,function(data)
            {
             if(data=='invalid')
              {
                $("#gmsgbox").fadeTo(200,0.1,function()
                {
                  $(this).html('Please enter a valid Group ID').addClass('messageboxerror').fadeTo(900,1);
                });     
              }
              else
              {
            $("#gmsgbox").fadeTo(200,0.1,function()  //start fading the messagebox
            {
              $(this).html('Group ID available').addClass('messageboxok').fadeTo(900,1);    
            });
             }
            }); 
        });
    });
+3
source share
2 answers

http://api.jquery.com/delay/

$("#group_id").blur(function() {
    $("#gmsgbox").delay(500).queue(function() {
        $("#gmsgbox").removeClass().addClass(//etc...
+6
source

Try setInterval(), clearInterval()

0
source

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


All Articles