Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery autocomplete get selected item text

I am wondering how to grab the selected item's text value on jquery autocomplete.

I have initialised jquery as following :

$(document).ready(function (){
    $("input#autocomplete").autocomplete({
        source: postcodelist,
        select: function (event, ui) {
            AutoCompleteSelectHandler(event, ui)
        }
    });
});

And I have created a function function AutoCompleteSelectHandler(event, ui) { }.

Inside this function I want to some extra handling to feed data into correct textboxes but I can't figure out how to grab the text value of the selected item.

I did google a bit and tried examples but I can't seem to get it working.

Any help will be much appreciated.

Thanks a lot advance.

like image 969
rlee923 Avatar asked Jun 21 '11 08:06

rlee923


1 Answers

The ui parameter has an item property with the selected text

function AutoCompleteSelectHandler(event, ui)
{               
    var selectedObj = ui.item;              
    alert(selectedObj.value);
}

source: http://jqueryui.com/demos/autocomplete/#event-select go to tab "Events" and then event "Select"

like image 185
GeertvdC Avatar answered Oct 05 '22 20:10

GeertvdC