I am having one heck of a hard time trying to figure this out. Been looking at examples and tools for JQuery validation for over 3 hours now.
All I want to do is require
To do this you have to use the :checked selector. Although JP's answer is fine, I'd probably do this:
$('#form1').submit(function() {
if ($('input:checkbox', this).is(':checked') &&
$('input:radio', this).is(':checked')) {
// everything's fine...
} else {
alert('Please select something!');
return false;
}
});
Couple of notes:
input before them, as they evaluate to *:checkbox and *:radio otherwise, which are very slow selectors.this as the second argument we are specifying a context for the search, and thus are only searching for checkboxes and radio inputs inside the current form. Without it we might get false positives if there happens to be another form in the page.