Skip to main content
Known Participant
November 19, 2020
Answered

List values in the field depending on the checked options

  • November 19, 2020
  • 2 replies
  • 735 views

I have options A, B, C, D, E and others. Depending on what I check, I want to list the corresponding values in the Risk field - if there is more than one, separated by commas. See attachment. Can you help me, please?

risk.pdf 

This topic has been closed for replies.
Correct answer try67

You can use this code as the custom calculation script of the "risks" field:

(Edit: code fixed)

 

 

var risks = [];
for (var i=1; i<=5; i++) {
	var v = this.getField("risk" + i).valueAsString;
	if (v!="Off") risks.push(v);
}
if (this.getField("risk6").valueAsString!="Off") risks.push(this.getField("other").valueAsString);
event.value = risks.join(", ");

 

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 19, 2020

You can use this code as the custom calculation script of the "risks" field:

(Edit: code fixed)

 

 

var risks = [];
for (var i=1; i<=5; i++) {
	var v = this.getField("risk" + i).valueAsString;
	if (v!="Off") risks.push(v);
}
if (this.getField("risk6").valueAsString!="Off") risks.push(this.getField("other").valueAsString);
event.value = risks.join(", ");

 

Inspiring
November 19, 2020

This will give error.

try67
Community Expert
Community Expert
November 19, 2020

What are the names of the check-boxes and text field (for the "Other" value)?

try67
Community Expert
Community Expert
November 19, 2020

Sorry, didn't notice your file had fields... I will post the code in a moment.