Evaluate if All Checkboxes are Checked.

  • Instructions:
    1. Install our free Custom Javascript for Gravity Forms plugin. Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
    2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.

Instructions

Code

Filename: gw-all-checkboxes-checked.js

/**
 * Gravity Wiz // Gravity Forms // Evaluate if All Checkboxes are Checked.
 * https://gravitywiz.com/
 *
 * Instruction Video: https://www.loom.com/share/e69c545358ca44748735ec98eee76a40
 *
 * * Instructions:
 *     1. Install our free Custom Javascript for Gravity Forms plugin.
 *        Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
 *     2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
 */
// Update "1" and "2" to the checkbox field id and hidden field id on your form
var checkboxFieldId = 1;
var hiddenFieldId   = 2;

function checkCheckboxCounts() {
	var $checkboxField = $( `#input_GFFORMID_${checkboxFieldId}` );
	$checkboxField.find( 'input' ).on( 'change', function() { 
		var totalCheckboxes   = $checkboxField.find( 'input' ).length;
		var checkedCheckboxes = $checkboxField.find( 'input:checked' ).length;
		if ( totalCheckboxes === checkedCheckboxes ) {
			$('#input_GFFORMID_' + hiddenFieldId).val(1).trigger( 'change' );
		} else {
			$('#input_GFFORMID_' + hiddenFieldId).val(0).trigger( 'change' );
		}
	} );
}

$( document ).on( 'gppa_updated_batch_fields', function() {
	checkCheckboxCounts();
} );

checkCheckboxCounts();

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.