Skip to main content
Henry.Ong
Inspiring
January 21, 2023
Answered

How to get the total of the row containing radio buttons?

  • January 21, 2023
  • 1 reply
  • 2350 views

I hope you can help with this issue.

I have created an assessment form with 12 rows that uses 4, 3, 2, 1, 0 radio buttons for rating.

What I wish is to total all those boxes with checks under Rating 4

a) Total all those boxes with check under Rating 4. Each check box would have a value of 4.

b) Total all those boxes with checks under Rating 3. Each check box would have a value of 3.

c) Total all those boxes with checks under Rating 2. Each check box would have a value of 2.

d) Total all those boxes with checks under Rating 1. Each check box would have a value of 1.

e) Total all those boxes with checks under Rating 0. Each check box would have a value of 0.

The result is placed on the Total (Row 11).

Example:

If Rating 4 of Rows 3, 6, and 9 are checked, the total would be 12

If Rating 3 of Rows 1, 2, 4, 5, and 7 are checked, the total would be 15

If Rating 2 of Rows 8 and 10 are checked, the total would be 4

 

Appreciate the help you can give. Thank you.

This topic has been closed for replies.
Correct answer Nesa Nurani

After the declaration of the fields array add either a semi-colon or a line-break:

"F02012"]

Thanks, good catch. I forgot to add semi-colon, to the script, but I had a line break, so it wasn't an error for me.
I added semi-colon to script above.

1 reply

Nesa Nurani
Community Expert
Community Expert
January 21, 2023

First remove calculations from all total fields you have, then use this in only one of the total fields as custom calculation script:

var total1 = 0,total2 = 0,total3 = 0,total4 = 0;
var fields = ["F02001","F02002","F02003","F02004","F02005","F02006","F02007","F02008","F02009","F02010","F02011","F02012"];
for(var i in fields){
if(this.getField(fields[i]).valueAsString == "1")total1+=1;
if(this.getField(fields[i]).valueAsString == "2")total2+=2;
if(this.getField(fields[i]).valueAsString == "3")total3+=3;
if(this.getField(fields[i]).valueAsString == "4")total4+=4;}
this.getField("F02013a").value = total4;
this.getField("F02013b").value = total3;
this.getField("F02013c").value = total2;
this.getField("F02013d").value = total1;

 

 

There is no point of calculating total of checkboxes with 0 since it will always be 0.

Henry.Ong
Henry.OngAuthor
Inspiring
January 24, 2023

Hi Nesa,

 

Appreciate the help but I am getting an error message saying "Syntax Error: missing; before statement 1: at line 2". See attached. Thank you.

try67
Community Expert
Community Expert
January 24, 2023

After the declaration of the fields array add either a semi-colon or a line-break:

"F02012"]