Skip to content

Instantly share code, notes, and snippets.

@aayushdrolia
Created October 21, 2017 11:10
Show Gist options
  • Save aayushdrolia/992d4494e73a8bc522e5950b1a4865d7 to your computer and use it in GitHub Desktop.
Save aayushdrolia/992d4494e73a8bc522e5950b1a4865d7 to your computer and use it in GitHub Desktop.
Restrict multiple select list to max of 2 selections
<script>
jQuery(document).ready(function($){
$('#subjects option').click(function()
{
var items = $(this).parent().val();
if (items.length > 2) {
alert("You can only select 2 values at a time");
$('#subjects option:selected').prop("selected",false);
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment