Count the number of times a condition is met within a Repeat Section using Script

The following Form Script will count the number of times a condition is met within a Repeat Section.

// This will test the condition just before the Form is saved. You could change this to test each time a Field is changed.

function FormBeforeSave(){
    
// This sets the counter 'cnt' to zero to start with.
    var cnt = 0;
    
    // This gets the Repeat Section and loops through the 'Test_rpt' for the relevant condition.
    // Change 'Test-rpt' to the relevant Repeat Section name.
    $('.repeat[data-repeat="Repeat_rpt"]').each(function() {
        
        // This loads the current 'row' of the Repeat Section into the variable 'rpt'.
        var rpt = $(this);
        
        // If the Field 'yn_1' is 'true' then the variable counter 'cnt' is increased by 1.
        if( rpt.find('[name$="yn_1"]').isTrue()){
            cnt ++;            
        } 
    });
    fld('Count_scr').val(cnt);
}

You can also test for multiple conditions using logic:

function FormBeforeSave(){
    
    // This sets the counter 'cnt' to zero to start with.
    var cnt = 0;
    
    // This gets the Repeat Section and loops through the 'Test_rpt' for the relevant condition.
    // Change 'Test-rpt' to the relevant Repeat Section name.
    $('.repeat[data-repeat="Repeat_rpt"]').each(function() {
        
        // This loads the current 'row' of the Repeat Section into the variable 'rpt'.
        var rpt = $(this);

        // If the Field 'yn_1' is 'true' and 'yn_2' is also true, then 'cnt' is increased by 1.
        if( (rpt.find('[name$="yn_1]"').isTrue() && rpt.find('[name$="yn_2]"').isTrue())   ){
            cnt ++;            
        } 

   });
    fld('Count_scr').val(cnt);
}

And another example with ‘OR’ logic:

function FormBeforeSave(){
    
    // This sets the counter 'cnt' to zero to start with.
    var cnt = 0;
    
    // This gets the Repeat Section and loops through the 'Test_rpt' for the relevant condition.
    // Change 'Test-rpt' to the relevant Repeat Section name.
    $('.repeat[data-repeat="Repeat_rpt"]').each(function() {
        
        // This loads the current 'row' of the Repeat Section into the variable 'rpt'.
        var rpt = $(this);

        // If the Field 'yn_1' is 'true' OR 'yn_2' is true, then 'cnt' is increased by 1.
        //if( (rpt.find('[name$="yn_1"]').isTrue() || rpt.find('[name$="yn_2"]').isTrue()) ){
            cnt ++;            
        } 

   });
    fld('Count_scr').val(cnt);
}

You can also test for other things, such as:

If a Field value is ‘false’ – using isFalse()
If a Field is checked – using isChecked()
If a Field has a certain value – using .val()==’Text’