javascript - change jquery chosen max_selected option dynamically -


i've 2 select option, class , class_attr class has 2 options: , b class_attr has many options: aa, bb, cc, dd, ee, ...

my question is, how implement if user choose a, chosen max_selected 5 options, , if user change b, chosen max_selected 3 options.

i'm trying this:

$(".class").change(function(){         var code = $(this).val();         if(code == 1){            $(".class_attr").chosen({max_selected_options: 5});             }         else{                $(".class_attr").chosen({max_selected_options: 3});                   }         $(".class_attr").trigger("liszt:updated"); }); 

but seems can't work, option list class_attr set once (the first class max_selected_options value selected, whether 5 or 3) , never updated max_selected_options after first time. thank you~

try this:

$('.class').chosen().change(function () {      var code = $(this).val();     var maxoptions = code == 1 ? 5 : 3;      $(".class_attr").chosen('destroy').chosen({ max_selected_options: maxoptions }); }); 

it looks can't change options after it's been initalised has destroyed before being created once more.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -