user3829086
user3829086

Reputation: 363

How to get the selected item value from auto-suggestion plugin

I am using the jQuery mobile auto suggestion plugin. I need to get the selected value from auto suggestion list and use it into some other function.

Here is my code :

<div data-role="content">
  <ul data-role="listview" data-filter="true" id="customer">
    <li class="ui-screen-hidden" ><a href="1">BMW</a></li>
    <li class="ui-screen-hidden" ><a href="2">Mercedez</a></li>
    <li class="ui-screen-hidden" ><a href="3">Ciat</a></li>
  </ul>
</div> 
function getItem() {
  //Here i want to get the selected item from list 
  //Like value of option "BMW" is "1" I want to get that 1 value
}

Upvotes: 1

Views: 107

Answers (1)

Irvin Dominin
Irvin Dominin

Reputation: 30993

You can get the clicked element by attaching and click handler and get the inner anchor href.

Code:

$(document).on("pagecreate", "#mypage", function () {
    $(document).on("click", "#customer li", function (e) {
        alert($(this).text() +" - " + $(this).find('a').attr('href'))
        e.preventDefault();
    });
});

Demo: http://jsfiddle.net/gkxgwx71/

Upvotes: 1

Related Questions