user485498
user485498

Reputation:

Get index of JQuery UI autocomplete element

I am using jQuery UI with a text box. When the user selects from the drop down list of possible matches, I want to get the index of the selection from the source array, assuing a JavaScript array.

Is there any way to do this?

Upvotes: 1

Views: 3136

Answers (1)

j08691
j08691

Reputation: 208012

You could do something like this:

select: function(event, ui) {
    console.log($.inArray(ui.item.value, availableTags));
}

where availableTags is the autocomplete's source array.

jsFiddle example

Upvotes: 2

Related Questions