0

my textbox has autocomplete functionality , where i have set autoFocus property to true

$( "#stateList" ).autocomplete({ autoFocus: true });

upon giving above property, my stateList autocomplete box get the first value selected and populated when user hits enter key or tab key.

i have been trying to achieve same functionality , when there is blur event on the "stateList" text box, and will automatically select the value which is been listed first.

my code here, where blur event is not been invoked http://jsfiddle.net/c6sWw/168/

pappu_kutty
  • 2,378
  • 8
  • 49
  • 93

2 Answers2

0

Try this:

$("#stateList").bind('autocompletechange', function(event, ui) {
    alert(ui.item.value);
});

DEMO

Kiran
  • 20,167
  • 11
  • 67
  • 99
0
$( "#stateList" ).autocomplete({
    autoFocus:true,
    source: states,
    open: function( event, ui ) {
        var firstElement = $(this).data("autocomplete").menu.element[0].children[0]
           , inpt = $('#stateList')
           
           , firstElementText = $(firstElement).text();
            inpt.val(firstElementText)
       
  
    }
 
})

Solved on jsfidle http://jsfiddle.net/c6sWw/170/

Reference jquery autocomplete auto fill field with 1st value and highligh added part

Community
  • 1
  • 1
Amit Garg
  • 3,867
  • 1
  • 27
  • 37