Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  70] [ 3]  / answers: 1 / hits: 76624  / 12 Years ago, thu, october 4, 2012, 12:00:00

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.


More From » jquery

 Answers
17

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


[#82761] Tuesday, October 2, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tristab

Total Points: 735
Total Questions: 106
Total Answers: 96

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
tristab questions
Sat, Sep 25, 21, 00:00, 3 Years ago
Sun, Jan 31, 21, 00:00, 3 Years ago
Wed, Dec 2, 20, 00:00, 4 Years ago
Fri, Oct 23, 20, 00:00, 4 Years ago
;