Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

count tick boxes in table column

Avatar

Former Community Member

Hi Guys,

I have a table and every cell has a tick box.

In the last row I want to calculate how many tick boxes have been checked in the column.

Could anyone advise on the best way to do this?

I'm assuming I need to set a variable to achieve this?

Any help is appreciated!

1 Accepted Solution

Avatar

Correct answer by
Level 10

For this to work you need a bit of prep work.

All the rows in the table need the same name (except header and footer) - if you've created a static table then they probably don't have the same name. Taking "Row1" as an example you want to name each row "Row1" and you'll see a number in brackets appear after the name (the instance number). All the checkboxes in a column need the same name as well - you'll want each column using a differently named checkbox. This also relies on the checkboxes having the default value for on and off (1 and 0) so we can count them.

The script, using FormCalc, reads through the rows and adds up the value of the named checkbox. Put it on the Calculate event:

$ = sum(Row1[*].CheckBox1)

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

For this to work you need a bit of prep work.

All the rows in the table need the same name (except header and footer) - if you've created a static table then they probably don't have the same name. Taking "Row1" as an example you want to name each row "Row1" and you'll see a number in brackets appear after the name (the instance number). All the checkboxes in a column need the same name as well - you'll want each column using a differently named checkbox. This also relies on the checkboxes having the default value for on and off (1 and 0) so we can count them.

The script, using FormCalc, reads through the rows and adds up the value of the named checkbox. Put it on the Calculate event:

$ = sum(Row1[*].CheckBox1)

Avatar

Former Community Member

Thanks Jono! Spot on! and i learnt something new!

Can this script work in Javascript too?

Avatar

Level 10

You can do it in JavaScript but it takes more code, you need a loop to go through and find the information. FormCalc is easier and calculates faster.

JavaScript (there are several ways of doing this, this is just one):

this.rawValue = null;

var total = 0;

var CB1 = this.resolveNodes("Table1.Row1[*].CheckBox");

for (i = 0; i < CB1.length; i ++) {

          total += CB1.item(i).rawValue;

}

total;