check that at least 1 checkbox is checked using jQuery Validate plugin

check that at least 1 checkbox is checked using jQuery Validate plugin

I'm trying to ensure that at least one checkbox is selected.  I'm using the query validate plugin.

here is the checkbox html
  1.  <!-- Checkbox -->
  2. <div class="control-group">
  3. <label class="control-label" for="checkboxes">Checkboxes</label>
  4. <div class="controls">
  5. <input type="checkbox" name="checkboxes[]" id='checkboxes' value="Students">Students<br>
  6.      <input type="checkbox" name="checkboxes[]" id='checkboxes' value="Alumni">Alumni<br>
  7.      <input type="checkbox" name="checkboxes[]" id='checkboxes' value="Business">Business<br>
  8.      <input type="checkbox" name="checkboxes[]" id='checkboxes' value="Faculty">Faculty<br>
  9. </div><!-- close controls -->
  10. </div> <!-- close control group -->



Here is my js
  1. $(document).ready(function(){

  2. // Validate
  3. // http://bassistance.de/jquery-plugins/jquery-plugin-validation/
  4. // http://docs.jquery.com/Plugins/Validation/
  5. // http://docs.jquery.com/Plugins/Validation/validate#toptions
  6. $('#contact-form').validate({
  7.    rules: {
  8.       
  9.      name: {
  10.        minlength: 2,
  11.        required: true
  12.      },
  13.       
  14.      email: {
  15.        required: true,
  16.        email: true
  17.      },
  18.       
  19.      subject: {
  20.       minlength: 2,
  21.        required: true
  22.      },
  23.       
  24.      message: {
  25.        minlength: 2,
  26.        required: true
  27.      },

  28.      select: {
  29.         
  30.        required: true
  31.      },

  32.      password: { 
  33.                 required: true, 
  34.                 minlength: 5 
  35.             }, 
  36.       
  37.      password_confirm: { 
  38.            required: true, 
  39.            minlength: 5, 
  40.            equalTo: "#password" 
  41.        },

  42.           checkboxes: { 
  43.            //required: true,
  44.            //minlength: 1
  45.             required: function(elem)
  46.             {
  47.                 return $("input.select:checked").length > 0;
  48.             }
  49.              
  50.           }
  51.    },
  52.    messages: { 
  53.             name: "Enter your name",

  54.             password: { 
  55.                 required: "Provide a password", 
  56.                 rangelength: jQuery.format("Enter at least {0} characters") 
  57.             },

  58.             password_confirm: { 
  59.                 required: "Repeat your password", 
  60.                 minlength: jQuery.format("Enter at least {0} characters"), 
  61.                 equalTo: "Enter the same password as above" 
  62.             }, 

  63.             email: { 
  64.                 required: "Please enter a valid email address", 
  65.                 minlength: "Please enter a valid email address", 
  66.                 remote: jQuery.format("{0} is already in use") 
  67.             },   
  68.             
  69.         },
  70.    highlight: function(label) {
  71.     $(label).closest('.control-group').addClass('error');
  72.    },
  73.    success: function(label) {
  74.     label
  75.     .text('OK!').addClass('valid')
  76.     .closest('.control-group').addClass('success');
  77.    }
  78.      
  79.  });
  80.   
  81. }); // end document.ready


I was trying to keep it as simple as possible and found this example here on site point but it doesn't seem to work how i'm using it. Also i have tried it with and without the array[] added onto the checkboxes. I'm using the [] to process it on the php side

  1. checkboxes: { 
  2.           
  3.             required: function(elem)
  4.             {
  5.                 return $("input.select:checked").length > 0;
  6.             }
  7.              
  8. }