Skip to main content
Jeff512
Inspiring
Mar 2, 2026 8:51 PM UTC
Answered

counting checkboxes

I feel like this is an easy issue?? but I'm not getting the Text box on page 12 (Next to the word Record) to add the check boxes.

I have an attendance roster (Page 12) and want a count of all Check Boxes checked.

I created a txt box at the top next to the word Record. 

I am aware that some code dose not like spaces. 

I thought it might be a syntaxes error. between “Check Box” and “CheckBox” so I adjusted the name of the boxes for the first 15 days in July to “CheckBox” . I have tried both.

 

// Initialize counter variable
var sum = 0; 
// Loop through the fields
for (var i = 126; i < 499; i += 1) {
// Add one if check box is not Off
    if (getField("CheckBox" + i).value !== "Off") {sum += 1;}
} 
// Set this field's value to the sum
event.value = sum;

    Jeff512
    Jeff512Correct answer
    Inspiring
    Mar 3, 2026 6:18 AM UTC

    Ok Solved

    for some reason “Check Box227” was missing.

    So Added a it and a “Check Box499” set the values to hidden and the code works great!!!

    9 replies

    JR Boulay
    Community Expert
    Community Expert
    Mar 3, 2026 6:04 PM UTC

    There is no need for JavaScript to perform such a simple calculation.
    See the attached example.

     

     

    Translate
    Acrobate du PDF, InDesigner et Photoshopographe
    Jeff512
    Jeff512Author
    Inspiring
    Mar 3, 2026 6:26 AM UTC

    Check Box227 not 127

    Translate
    Jeff512
    Jeff512AuthorCorrect answer
    Inspiring
    Mar 3, 2026 6:18 AM UTC

    Ok Solved

    for some reason “Check Box227” was missing.

    So Added a it and a “Check Box499” set the values to hidden and the code works great!!!

    Translate
    try67
    Community Expert
    Community Expert
    Mar 2, 2026 11:22 PM UTC

    Add this line inside your loop:

    console.println(i);

    Then open the JS console, and tick one of the fields, and you’ll see what the issue is.

    Translate
    Jeff512
    Jeff512Author
    Inspiring
    Mar 2, 2026 11:58 PM UTC

    Ok output “Is null”??

    I tried changing the output value to 1 before I sent the request for help/

    so what’s the solution.???

    Translate
    try67
    Community Expert
    Community Expert
    Mar 3, 2026 12:03 AM UTC

    The issue is that some of the field names you're trying to access are incorrect. The code I provided will help you locate which ones, as it will be the last number shown in the list before the code errors out.

    Translate