Last Updated: February 25, 2016
·
857
· esbanarango

Set the number of choices available using multiple select with Chosen.js .

Sometimes when you're using Chosen.js's Multiple Select you want restrict the number of choices. Here a little code snippet to achieve it.

In this example I want the user to choose maximum 2 options

$('#id').chosen().change(function(event) { 
  if($(this).val()!=null){
    if ($(this).val().length > 1) {
      $(".chzn-drop").css("display","none");
    }
    if ($(this).val().length < 2) {
      $(".chzn-drop").css("display","block");
    }
  }
});

1 Response
Add your response

Thank you so much, dude!

over 1 year ago ·