Last active
March 8, 2021 16:51
-
-
Save guidoeffe/a542faae45bd7f2a286e329cbeebeb33 to your computer and use it in GitHub Desktop.
CF7 limit number of choises in checkboxes
This file contains 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
jQuery(function(){ | |
limitCheck('Q3',2); | |
limitCheck('Q4',3); | |
limitCheck('Q9',2); | |
limitCheck('Q12',4); | |
function limitCheck(idElement,maxChoises ){ | |
var checkboxes = jQuery('#'+idElement+' input[type="checkbox"]'); | |
checkboxes.change(function(){ | |
var current = checkboxes.filter(':checked').length; | |
checkboxes.filter(':not(:checked)').prop('disabled', current >= maxChoises); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment