Created
February 13, 2019 14:26
-
-
Save mgrubinger/c7f293d16df2a3092fda855b092e536a to your computer and use it in GitHub Desktop.
Limit the maximum of currently selected options for a selectbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var verified = []; | |
document.querySelector('#myselector').onchange = function(e) { | |
if (this.querySelectorAll('option:checked').length <= 3) { | |
verified = Array.apply(null, this.querySelectorAll('option:checked')); | |
} else { | |
Array.apply(null, this.querySelectorAll('option')).forEach(function(e) { | |
e.selected = verified.indexOf(e) > -1; | |
}); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment