Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

List values in the field depending on the checked options

New Here ,
Nov 19, 2020 Nov 19, 2020

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 

TOPICS
Acrobat SDK and JavaScript
788
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 19, 2020 Nov 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(", ");

 

Translate
Community Expert ,
Nov 19, 2020 Nov 19, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2020 Nov 19, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2020 Nov 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(", ");

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 19, 2020 Nov 19, 2020

This will give error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 19, 2020 Nov 19, 2020

Thanks a lot! It works perfectly! I must only add code 

var v = this.getField("risk" + i).value;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2020 Nov 19, 2020
LATEST

Yeah, sorry. Don't know what happened there... I fixed it now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines