Question

I'm using this code to validate an input field, but I don't want it to pull the text from the field until half a second after the field loses focus. How can I do that?

$(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);    
            });
             }
            }); 
        });
    });
Was it helpful?

Solution

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

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

OTHER TIPS

Try By setInterval(), clearInterval()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top