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

If/Else Statement PDF Form

New Here ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

Hi Adobe Community,

I am just starting out in learning how to use javascript in the custom calculation script. I am creating a check checklist where each check box equals a value of 1, and that value is totaled at the base of the check list in box A (steps completed.) My next goal is to have the box below (B) either show "NO" or "YES" depending on the value of A. For example, there are 17 steps so if A's value is 0-16 B would be NO and if the value is 17 than it would say YES - meaning the check list is complete or not. Right now, I can only every get B to always say NO or always say YES. I know I am probably making a very basic mistake, but if anyone can help me with my code I would really appreciate it. And is it possible to color the text so that NO would be in red or YES would be green, or is that only possible in excel? Thanks in advance!

var v1 = this.getField("A").value;

var v2 = this.getField("B").value;

if (v1 = 0) event.value = "NO";

else if (v1 = 1) event.value = "NO";

else if (v1 = 2) event.value ="NO";

else if (v1 = 3) event.value = "NO";

else if (v1 = 4) event.value = "NO";

else if (v1 = 5) event.value = "NO";

else if (v1 = 6) event.value = "NO";

else if (v1 = 7) event.value = "NO";

else if (v1 = 8) event.value = "NO";

else if (v1 = 9) event.value = "NO";

else if (v1 = 10) event.value = "NO";

else if (v1 = 11) event.value = "NO";

else if (v1 = 12) event.value = "NO";

else if (v1 = 13) event.value = "NO";

else if (v1 = 14) event.value = "NO";

else if (v1 = 15) event.value = "NO";

else if (v1 = 16) event.value = "NO";

else if (v1 = 17) event.value = "YES";

TOPICS
Acrobat SDK and JavaScript , Windows

Views

797

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
community guidelines

correct answers 1 Correct answer

Engaged , May 10, 2018 May 10, 2018

It is definitly not the correct way to achieve this, lol

put this in the custom calculation of the "B" field:

var v1 = this.getField("A").value;

if (v1 == 17) event.value = "YES"

else event.value = "NO"

Notice that when using an if statement, the correct comparison operator is "=="    , not "=".

Based on what you describe, you do not need to have a field that totals the number of checked boxes.  You could all do that via JS.  A loop would go through all your checkboxes, count how many are checked, and

...

Likes

Translate

Translate
Engaged ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

It is definitly not the correct way to achieve this, lol

put this in the custom calculation of the "B" field:

var v1 = this.getField("A").value;

if (v1 == 17) event.value = "YES"

else event.value = "NO"

Notice that when using an if statement, the correct comparison operator is "=="    , not "=".

Based on what you describe, you do not need to have a field that totals the number of checked boxes.  You could all do that via JS.  A loop would go through all your checkboxes, count how many are checked, and go on with the script I provided.

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
community guidelines
New Here ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

LATEST

That was a lot simpler than I was making it. Thank you!!

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
community guidelines