"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.
- <div class="form-group" id="backgrounds_picker">
- <label class="col-md-4 control-label" for="checkboxes">
- Select any desired backgrounds:</label>
- <div class="col-md-4">
- <label class="checkbox-inline" for="checkboxes-0">
- <input name="checkboxes" id="checkboxes-0" type="checkbox" value="blank">
- Blanks
- </label>
- <label class="checkbox-inline" for="checkboxes-1">
- <input name="checkboxes" id="checkboxes-1" type="checkbox" value="fresh">
- Fresh Water
- </label>
- <label class="checkbox-inline" for="checkboxes-2">
- <input name="checkboxes" id="checkboxes-2" type="checkbox" value="marine">
- Marine Water
- </label>
- <label class="checkbox-inline" for="checkboxes-3">
- <input name="checkboxes" id="checkboxes-3" type="checkbox" value="rain">
- Rain
- </label>
- <label class="checkbox-inline" for="checkboxes-4">
- <input name="checkboxes" id="checkboxes-4" type="checkbox" value="none" checked="checked">
- None
- </label>
- </div>
- </div>
- <div id="fields">
- <div id="blank_co" class="form-group">
- <label class="col-md-4 control-label" for="blankbg">Blanks cutoff: (1-99)</label>
- <div class="col-md-4">
- <input name="blankbg" class="form-control input-md" id="blankbg" required="" type="text" placeholder="" value="10">
- </div>
- </div>
- <div id="fresh_co" class="form-group">
- <label class="col-md-4 control-label" for="freshbg">Fresh water cutoff: (1-99)</label>
- <div class="col-md-4">
- <input name="freshbg" class="form-control input-md" id="freshbg" required="" type="text" placeholder="" value="10">
- </div>
- </div>
- <div id="marine_co" class="form-group">
- <label class="col-md-4 control-label" for="marinebg">Marine water cutoff: (1-99)</label>
- <div class="col-md-4">
- <input name="marinebg" class="form-control input-md" id="marinebg" required="" type="text" placeholder="" value="10">
- </div>
- </div>
- <div id="rain_co" class="form-group">
- <label class="col-md-4 control-label" for="rainbg">Rain water cutoff: (1-99)</label>
- <div class="col-md-4">
- <input name="rainbg" class="form-control input-md" id="rainbg" required="" type="text" placeholder="" value="10">
- </div>
- </div>
- </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.
- var $check = $('#backgrounds_picker input[type="checkbox"][value!="none"]'),
- $none = $('input[type="checkbox"][value="none"]'),
- $groups = $('#fields .form-group');
-
- var uncheckAll = function() {
- if ($(this).is(':checked')) {
- $check.not(this).prop('checked', false);
- }
- }
- var uncheckNone = function() {
- if ($(this).is(':checked')) {
- $none.prop('checked', false);
- }
- }
- var hideGroup = function(){
- $groups.fadeOut();
- }
- var toggleGroup = function(){
- var groupId = $(this).val();
- if ($(this).is(':checked')) {
- $('#' + groupId + '_co').fadeIn();
- } else {
- $('#' + groupId + '_co').fadeOut();
- }
- }
- $none.on('change', function(){
- uncheckAll();
- hideGroup();
- });
- $check.on('change', function(){
- uncheckNone();
- toggleGroup();
- });
Where is my mistake?