"Cannot read property 'toLowerCase' of undefined" in checkbox related script

"Cannot read property 'toLowerCase' of undefined" in checkbox related script

I have a set of checkboxes that are intended to toggle the visibility of corresponding form groups.

  1. <div class="form-group" id="backgrounds_picker">
  2.   <label class="col-md-4 control-label" for="checkboxes">
  3.     Select any desired backgrounds:</label>
  4.   <div class="col-md-4">
  5.     <label class="checkbox-inline" for="checkboxes-0">
  6.           <input name="checkboxes" id="checkboxes-0" type="checkbox" value="blank">
  7.           Blanks
  8.         </label>
  9.     <label class="checkbox-inline" for="checkboxes-1">
  10.           <input name="checkboxes" id="checkboxes-1" type="checkbox" value="fresh">
  11.           Fresh Water
  12.         </label>
  13.     <label class="checkbox-inline" for="checkboxes-2">
  14.           <input name="checkboxes" id="checkboxes-2" type="checkbox" value="marine">
  15.           Marine Water
  16.         </label>
  17.     <label class="checkbox-inline" for="checkboxes-3">
  18.           <input name="checkboxes" id="checkboxes-3" type="checkbox" value="rain">
  19.           Rain
  20.         </label>
  21.     <label class="checkbox-inline" for="checkboxes-4">
  22.           <input name="checkboxes" id="checkboxes-4" type="checkbox" value="none" checked="checked">
  23.           None
  24.         </label>
  25.   </div>
  26. </div>

  27. <div id="fields">
  28.   <div id="blank_co" class="form-group">
  29.     <label class="col-md-4 control-label" for="blankbg">Blanks cutoff: (1-99)</label>
  30.     <div class="col-md-4">
  31.       <input name="blankbg" class="form-control input-md" id="blankbg" required="" type="text" placeholder="" value="10">
  32.     </div>
  33.   </div>

  34.   <div id="fresh_co" class="form-group">
  35.     <label class="col-md-4 control-label" for="freshbg">Fresh water cutoff: (1-99)</label>
  36.     <div class="col-md-4">
  37.       <input name="freshbg" class="form-control input-md" id="freshbg" required="" type="text" placeholder="" value="10">
  38.     </div>
  39.   </div>

  40.   <div id="marine_co" class="form-group">
  41.     <label class="col-md-4 control-label" for="marinebg">Marine water cutoff: (1-99)</label>
  42.     <div class="col-md-4">
  43.       <input name="marinebg" class="form-control input-md" id="marinebg" required="" type="text" placeholder="" value="10">
  44.     </div>
  45.   </div>

  46.   <div id="rain_co" class="form-group">
  47.     <label class="col-md-4 control-label" for="rainbg">Rain water cutoff: (1-99)</label>
  48.     <div class="col-md-4">
  49.       <input name="rainbg" class="form-control input-md" id="rainbg" required="" type="text" placeholder="" value="10">
  50.     </div>
  51.   </div>
  52. </div>

The script I have written for the above HTML gives a "Cannot read property 'toLowerCase' of undefined" error in the console instead of just... working.

  1. var $check = $('#backgrounds_picker input[type="checkbox"][value!="none"]'),
  2.   $none = $('input[type="checkbox"][value="none"]'),
  3.     $groups = $('#fields .form-group');
  4.     
  5. var uncheckAll = function() {
  6.   if ($(this).is(':checked')) {
  7.     $check.not(this).prop('checked', false);
  8.   }
  9. }

  10. var uncheckNone = function() {
  11.   if ($(this).is(':checked')) {
  12.     $none.prop('checked', false);
  13.   }
  14. }

  15. var hideGroup = function(){
  16. $groups.fadeOut();
  17. }

  18. var toggleGroup = function(){
  19. var groupId = $(this).val();
  20.   if ($(this).is(':checked')) {
  21.   $('#' + groupId + '_co').fadeIn();
  22.   } else {
  23.   $('#' + groupId + '_co').fadeOut();
  24.   }
  25. }

  26. $none.on('change', function(){
  27. uncheckAll();
  28.   hideGroup();
  29. });

  30. $check.on('change', function(){
  31. uncheckNone();
  32.   toggleGroup();
  33. });

Where is my mistake?