Last active
August 29, 2015 14:21
-
-
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.
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 ( $ ) { | |
$.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