Skip to content

Instantly share code, notes, and snippets.

@ethanclevenger91
Last active August 29, 2015 14:21
Show Gist options
  • Save ethanclevenger91/af5e55e9062414ef3e6e to your computer and use it in GitHub Desktop.
Save ethanclevenger91/af5e55e9062414ef3e6e to your computer and use it in GitHub Desktop.
Check if at least one of a group of checkboxes has been checked.
(function ( $ ) {
$.fn.oneChecked = function() {
var checked = false;
this.each(function() {
if($(this).is(':checked')) {
checked = true;
}
});
return checked;
};
}( jQuery ));
//use
jQuery('form').submit(function() {
if(!jQuery('input[name="fizz[]"]').oneChecked()) {
alert('Must pick one!');
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment