Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
93
rated 0 times [  96] [ 3]  / answers: 1 / hits: 52743  / 11 Years ago, thu, march 14, 2013, 12:00:00

I'm using Chosen Multiple Select
What I want to do is that if user selects any option I want that value and then I will do some functionality depending on that value.



In chosen without multiple select i can get selected value by using foll. code



$(.selectId).chosen().change(function(){
selectedValue = $(this).find(option:selected).val();
});


But in multiple select I get the first selected value again n again
can anybody help me by finding the current selected value in multiple select element??


More From » jquery

 Answers
8

The Chosen documentation mentions parameters for getting the most recently changed variables.




Chosen triggers the standard DOM event whenever a selection is made
(it also sends a selected or deselected parameter that tells you
which option was changed).




So, if you just want the most recent option selected or deselected:



$(.selectId).chosen().change(function(e, params){
// params.selected and params.deselected will now contain the values of the
// or deselected elements.
});


Otherwise if you want the whole array to work with you can use:



$(.selectId).chosen().change(function(e, params){
values = $(.selectId).chosen().val();
//values is an array containing all the results.
});

[#79607] Tuesday, March 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenamackennac

Total Points: 304
Total Questions: 110
Total Answers: 107

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
jenamackennac questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Wed, Apr 21, 21, 00:00, 3 Years ago
Thu, Apr 1, 21, 00:00, 3 Years ago
Tue, Feb 2, 21, 00:00, 3 Years ago
;