Created
February 19, 2016 22:39
-
-
Save picandocodigo/72befb2107cf60cfbc80 to your computer and use it in GitHub Desktop.
Limit a <select> checked count
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
// interests is a <select multiple> element | |
var interests = document.getElementById('interests'); | |
interests.addEventListener('change', function(event){ | |
var selected = this.querySelectorAll("option:checked"); | |
if (selected.length > 3){ | |
selected[0].selected = false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment