I need to get the count of the checkbox script but is not working correctly

Cherly
Tera Contributor

-I need to get the count of the checkbox script but is not working correctly. i keep giving the result of 4 regardless of what i select. the script below was what i created. 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}

// Replace the following variable names with the actual names of your checkboxes
var checkboxVars = ['ac_photoshop','ac_illustrato','ac_indesign','ac_premiere'];

var selectedCount = 0;
for (var i = 0; i < checkboxVars.length; i++) {
if (g_form.getValue(checkboxVars[i]) === 'true') {
selectedCount++;
}
}

g_form.setValue('checkbox_count', selectedCount);
}

1 ACCEPTED SOLUTION

Chaitanya Redd1
Tera Guru

Hi,

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    // Replace the following variable names with the actual names of your checkboxes
    var checkboxVars = ['ac_photoshop','ac_illustrato','ac_indesign','ac_premiere'];

    var selectedCount = 0;
    for (var i = 0; i < checkboxVars.length; i++) {
        // Check if the checkbox is true (boolean), not a string 'true'
        if (g_form.getValue(checkboxVars[i]) == true) {
            selectedCount++;
        }
    }

    // Update the field with the count
    g_form.setValue('checkbox_count', selectedCount);
}

View solution in original post

1 REPLY 1

Chaitanya Redd1
Tera Guru

Hi,

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    // Replace the following variable names with the actual names of your checkboxes
    var checkboxVars = ['ac_photoshop','ac_illustrato','ac_indesign','ac_premiere'];

    var selectedCount = 0;
    for (var i = 0; i < checkboxVars.length; i++) {
        // Check if the checkbox is true (boolean), not a string 'true'
        if (g_form.getValue(checkboxVars[i]) == true) {
            selectedCount++;
        }
    }

    // Update the field with the count
    g_form.setValue('checkbox_count', selectedCount);
}