Damith Ganegoda
Damith Ganegoda

Reputation: 4328

jquery autocomplete for keypress event

I create comment box like a facebook comment box. I have to do like this in textarea box type @ sign and after I type letter then detect this letter or letters and popup friend list.

$("textarea#event_message").autocomplete("friendsAutoComplete");

this method used for autocomplete that works fine. but want this method fire after type @ sign.

I tried this way

$('textarea#event_message').keypress(function(event) {
      if(event.which == 64) {
            $('textarea#event_message').autocomplete("friendsAutoComplete");
       }
}); 

and I also tried jquery live method

It doesn't like work.How can I solve that problem?

Upvotes: 0

Views: 5658

Answers (1)

Quincy
Quincy

Reputation: 4433

First of all, what is the string "friendsAutoComplete" you referring?

To fire a search using an initialized autocomplete widget, you should call the search method instead.

http://jqueryui.com/demos/autocomplete/

So you may try out

$('textarea#event_message').keypress(function(event) {
      if(event.which == 64) {
            $('textarea#event_message').autocomplete("search");
       }
});

Upvotes: 1

Related Questions