0

I am trying to call a function every time an autocomplete search is changed, either by key press or by clicking one of the options of the autocomplete. Key press works fine like this...

 $('#searchScenario').on('keyup change', function () {
 //event
 }

But this won't work when I click on one of the autocomplete options.

Here is my autocomplete initialization.

 scenarioSearch = $('#searchScenario').autocomplete({
        source: scenarioTags,
        minLength: 0
    }).focus(function () {
        $(this).autocomplete('search', $(this).val());
    });

I have attempted other methods such as this...

(function () {  
var scenarioSearch = $("#searchScenario").autocomplete({ 
  change: function() {
      alert('changed');
  }
  });
  scenarioSearch .autocomplete('option','change').call(scenarioSearch );
  });

But it only triggers when the box loses focus.

Any help would be greatly appreciated.

OneTwo
  • 2,291
  • 6
  • 33
  • 55
  • There's no one-size-fit-all autocomplete event for what you describe. Try assigning the same handler to the [non-widget `input` event](http://stackoverflow.com/questions/1481152) and [the widget's `select` event](http://api.jqueryui.com/autocomplete/#event-select) – blgt Nov 28 '14 at 11:58

1 Answers1

1

I am not at my box but can you try it using :

select:function() {
      alert('changed');
  }

Or

.select()
deepakborania
  • 166
  • 2
  • 8