Skip to content

Instantly share code, notes, and snippets.

@guidoeffe
Last active March 8, 2021 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guidoeffe/a542faae45bd7f2a286e329cbeebeb33 to your computer and use it in GitHub Desktop.
Save guidoeffe/a542faae45bd7f2a286e329cbeebeb33 to your computer and use it in GitHub Desktop.
CF7 limit number of choises in checkboxes
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