Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vince844/49ac5d6636734295c17d944ec18f79dd to your computer and use it in GitHub Desktop.
Save vince844/49ac5d6636734295c17d944ec18f79dd to your computer and use it in GitHub Desktop.
Gravity Form passing value from checkbox to text field
<script>
var checkboxHandler = {
//Change these IDs to match your form
checkboxFieldId: 'input_1_25', //checkbox container ID
outputFieldId: 'input_1_23', //hidden field to capture values
checkboxField: null,
outputField: null,
init: function() {
this.outputField = document.getElementById(this.outputFieldId);
if( typeof this.outputField === 'undefined' || !this.outputField ) {
console.error('Missing output field ' + this.outputFieldId);
return;
}
this.checkboxField = document.getElementById(this.checkboxFieldId);
if(typeof this.checkboxField === 'undefined' || !this.checkboxField) {
console.error('Missing checkbox field ' + this.checkboxFieldId);
return;
}
jQuery(this.checkboxField).on(
'change',
'input[type=checkbox]',
{
checkbox: this.checkboxField,
output: this.outputField
},
this.setValues
);
},
setValues: function(ev) {
var fields = ev.data;
var valueString = '';
jQuery(fields.checkbox).find('input:checked').each( function(i){
valueString += this.value + ', ';
});
fields.output.value = valueString.replace(/, $/, '');
}
};
jQuery().ready( checkboxHandler.init() );
</script>
You can put this javascript snippet into a html field inside the gravity form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment