Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

javascript - Jquery autocomplete on select event

I am using jQuery autocomplete and its working fine, now I want to store a variable in session from jQuery when following condition occurs.

When someone types any word jQuery shows suggestion dropdown, if someone select an item from that suggestion dropdown.

I want to capture above point and store a variable in session.

I searched Google, StackOverflow but find no relevant solution. My code for autocomplete is following:

  $(".autosearch-smart").autocomplete('Home/GetCompanyNames', {
    minChars: 1,
    width: 402,
    matchContains: "word",
    autoFill: true
});

and this is what I tried to do:

  $(".autosearch-smart").autocomplete('Home/GetCompanyNames', {
    minChars: 1,
    width: 402,
    matchContains: "word",
    autoFill: true,
    select: function (a, b) {
        alert("selected");
    }

});

EDIT : Select event handler is also not working

I am using asp.net MVC3 with C#. Please help me out and thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So if I understand correctly you want to store the selected value in a variable sessions

you can get the value out of the selected item through following code:

  $(".autosearch-smart").autocomplete('Home/GetCompanyNames', {
minChars: 1,
width: 402,
matchContains: "word",
autoFill: true,
select: function (event, ui) {
    var label = ui.item.label;
    var value = ui.item.value;
   //store in session
  document.valueSelectedForAutocomplete = value 
}
});

the value and label are json objects that came from the server

Hope this helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...