views:

33

answers:

1

Is there a way to stop the ui jquery autocomplete if the user leaves the page looking at the Documentation here I see many things

 .autocomplete( "destroy" )
.autocomplete( "disable" )
.autocomplete( "close" )

but how do i use them after a use leaves the field

    $("#request_song").autocomplete({
        source: function(req, add){
            $.getJSON('<%= ajax_path("trackName") %>', req, function(data) {
      var suggestions = data.suggestions;
                add(suggestions);
            });
        },
        change: function() {
            var main = $('#main_content');
            main.empty().append("<img id=\"throbber\" src='/pre_config/css/images/throbber.gif' alt='Loading. Please wait.' />");
            $("#band_events").load("/load_events/"+ escape($('#request_artist').val()), successCallback );
        },
    });
+1  A: 

Bind a blur event handler to the field (essentially a lost-focus event):

$("#request_song").blur(function(){
    // Using disable and close after destroy is redundant; just use destroy
    $(this).autocomplete("destroy");
});
SimpleCoder
can i add two selectors at the same time like $("#request_song", "#request_artist").blur(function(){
Matt
You were close: `$("#request_song, #request_artist").blur(function(){`
SimpleCoder