I want to deselect last selected option from listbox if he select maximum 8 options from listbox.if he select next ninth option then there should be alert like below in code and automatic deselect that ninth option.
<script>
$(document).ready(function () {
$("#SelectedIndustryList")
.change(function () {
var sel = [];
$("#SelectedIndustryList option:selected").each(function () {
//str += $(this).text() + " ";
var count = $("#SelectedIndustryList option:selected").length;
if (count > 8) {
//var selectedItem = $("#SelectedIndustryList option:selected").index();
$('#lbl_msg').html("You can select only maximum 8 Industries.");
$('#msgBox').show();
}
});
})
.trigger("change");
});
</script>