jquery ui autocomplete index of the item i selected

i'm using the jquery ui autocomplete plugin

After I select an item from the autocomplete.

I call the selected value value using ui.item.value and the works fine.
For example my autocomplete is show last names:


When I select Williams ui.item.value returns Williams .

How do I get the index of the item i selected? Anyone know the syntax

So if I select Williams from the 3 last names that show up i want the index for the 3rd item, which i believ is 2.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongSoftware Team LeadCommented:
How do I get the index of the item i selected? Anyone know the syntax
it can be done, but more like to set an attribute in your item list.

below modified version from an online test site:

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
        $(function () {
            var availableTags = [
                              {label: "ActionScript", index:1},
                              {label: "AppleScript", index:2},
                              {label: "Asp", index:3},
                              {label: "BASIC", index:4},
                              {label: "C", index:5},
                              {label: "C++", index:6},
                              {label: "Clojure", index:7},
                              {label: "COBOL", index:8},
                              {label: "ColdFusion", index:9},
                              {label: "Erlang", index:10},
                              {label: "Fortran", index:11},
                              {label: "Groovy", index:12},
                              {label: "Haskell", index:13},
                              {label: "Java", index:14},
                              {label: "JavaScript", index:15},
                              {label: "Lisp", index:16},
                              {label: "Perl", index:17},
                              {label: "PHP", index:18},
                              {label: "Python", index:19},
                              {label: "Ruby", index:20},
                              {label: "Scala", index:21},
                              {label: "Scheme", index:22},
                source: availableTags,
                select: function (event, ui) { alert(ui.item.index); }
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maqskywalkerAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.