2009-09-22 5 views

Répondre

1
$('#form').submit(function(e) { 
    var errorElements = [], valid = false; 

$('.checkboxgroup', this).each(function() { 
     var checkBoxes = $(':checkbox', this), oneChecked = false; 
     checkBoxes.each(function() { 
      if (!oneChecked && !$(this).is(':checked')) { 
       valid = false; 
       errorElements.push(this); 
      } else { 
       oneChecked = true; 
      } 
     }); 
    }); 

    e.preventDefault(); // cancels form submit.. remove if you dont need. 

    if (errorElements.length) { 
    // code to do what you want if it fails 
    } else { 
    // code to do what you want if it passes 
    } 


}); 

html:

<div class="checkboxgroup"> 

(checkbox html) 

</div> 


<div class="checkboxgroup"> 

(checkbox html) 

</div> 
Questions connexes