0

Im trying to attach a simple click event with jquery autocomplete. This is the code Im using:

$("#term").autocomplete({

  source: function( request, response ) {
    $.ajax({
      url: 'http://query.yahooapis.com/v1/public/yql',
      dataType: 'JSONP',
      data: {
        format: 'json',
        q: 'select * from xml where url="http://google.com/complete/search?output=toolbar&q=' + escape(request.term) + '"'
      },
      success: function(data) {
        response($.map(data.query.results.toplevel.CompleteSuggestion, function(item) {
          return { label: item.suggestion.data, value: item.suggestion.data };
        }));
      }
    });
  }
}); 

I would like to be able to click the list item which will then trigger another request (ea populated another list) I want to do this with the jquery click event, so far no good, see this LINK

1

1 Answer 1

4

You can use select event in autocomplete.

$("#term").autocomplete({
     select:function(event, ui){
          // do your things here
      },

  source: function( request, response ) {
    $.ajax({
      url: 'http://query.yahooapis.com/v1/public/yql',
      dataType: 'JSONP',
               data: {
        format: 'json',
        q: 'select * from xml where url="http://google.com/complete/search?output=toolbar&q=' + escape(request.term) + '"'
      },
      success: function(data) {
        response($.map(data.query.results.toplevel.CompleteSuggestion, function(item) {
          return { label: item.suggestion.data, value: item.suggestion.data };
        }));
      }
    });
  }
}); 

Or else you can do like this in your way

$(".ui-menu-item a").on('click',function() {

See its working here

Sign up to request clarification or add additional context in comments.

2 Comments

I think I have to get the value of list item, I will look in to it and when it works I will accept answer
See I have edited now. I had done a mistake too. Try now with my new code .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.