Skip to main content
Participant
May 10, 2023
Answered

Sum the values in one text box from another set of text boxes based on checkbox selection.

  • May 10, 2023
  • 1 reply
  • 561 views

I am trying to sum the values in one text box from another set of text boxes if the corresponding checkbox is selected.

 

I would like Text 100 to be the sum of any value in Text 360, Text 367, Text 374 and/or Text 381 if the corresponding checkbox is selected. The corresponding checkboxes are

Text 360 would be linked to Check Box 27

Text 367 would be linked to Check Box 29

Text 374 would be linked to Check Box 31

Text 381 would be linked to Check Box 33

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

Use this as 'Custom calculation script' of "Text 100":

var total = 0;
var cText = ["Text 360","Text 367","Text 374","Text 381"];
var cCheck = ["Check Box 27","Check Box 29","Check Box 31","Check Box 33"];

for(var i in cCheck){
if(this.getField(cCheck[i]).valueAsString != "Off")
total += Number(this.getField(cText[i]).valueAsString);}

event.value = total;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
May 19, 2023

Use this as 'Custom calculation script' of "Text 100":

var total = 0;
var cText = ["Text 360","Text 367","Text 374","Text 381"];
var cCheck = ["Check Box 27","Check Box 29","Check Box 31","Check Box 33"];

for(var i in cCheck){
if(this.getField(cCheck[i]).valueAsString != "Off")
total += Number(this.getField(cText[i]).valueAsString);}

event.value = total;