I\'m using a select tag in a form I\'m making that allows multiple selections, but I want to make the maximum amount of selections upto 10. Is this possible using javascript
You can use jQuery
$("select").change(function () {
if($("select option:selected").length > 3) {
//your code here
}
});
I basically merged a couple of the provided answers to make something specific to a particular ID:
$("#mySelect").on("click", "option", function(){
var max = 3;
if ( max <= $(this).siblings(":selected").length ) {
alert("Only " + max + " selections allowed.");
$(this).removeAttr("selected");
}
});
Rob