Hi i’m using gravity form plugin and i’ve manageed to pass the value of a checkbox option to another field using the following javascript code.
<script>
var checkboxHandler = {
//Change these IDs to match your form
checkboxFieldId: 'input_1_1', //checkbox container ID
outputFieldId: 'input_1_2', //hidden field to capture values
checkboxField: null,
outputField: null,
/*
Listen to Checkboxes
---------------------- */
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
);
},
/*
Set text (or hidden) field to list of checkbox values
----------------------------------- */
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>
Is it possible to pass the text for each option instead of the values? Many thanks