Highlighted

List values in the field depending on the checked options

New Here ,
Nov 19, 2020

Copy link to clipboard

Copied

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 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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(", ");

 

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

39

Likes

Translate

Translate

Report

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

List values in the field depending on the checked options

New Here ,
Nov 19, 2020

Copy link to clipboard

Copied

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 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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(", ");

 

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

40

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 19, 2020 0
Most Valuable Participant ,
Nov 19, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 19, 2020 0
Most Valuable Participant ,
Nov 19, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 19, 2020 0
Most Valuable Participant ,
Nov 19, 2020

Copy link to clipboard

Copied

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(", ");

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 19, 2020 0
Contributor ,
Nov 19, 2020

Copy link to clipboard

Copied

This will give error.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

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

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 19, 2020 0
try67 LATEST
Most Valuable Participant ,
Nov 19, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 19, 2020 0