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

Populate field based on data entered in another field

New Here ,
Feb 02, 2016 Feb 02, 2016

I'm working on a document that will have benefit plan pricing levels at the top. In the column below there are individual fields for each of the various benefit options. The co-pay cost for these options will depend on what the monthly contribution is which is the value entered at the top.

Assuming my range of monthly contributions are $100, $125 & $150 I'm looking for a script that I can customize for each subsequent field that would, I'm assuming do the following:

  • Get the value from the primary field "PlanBenefit01":
    • If value in PlanBenefit01 is "$100" enter "XXX" in the field
    • If value in PlanBenefit01 is "$125" enter "YYY" in the field
    • If value in PlanBenefit01 is "$150" enter "ZZZ" in the field

I'm assuming that this would be entered in the "Properties>Calculate>Custom Calculation Script" section for the field as another recent solution was. If so please confirm. If not, kindly provide me with guidance on where to insert this?

Thanks again to one and all.

TOPICS
Acrobat SDK and JavaScript , Windows
797
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 , Feb 02, 2016 Feb 02, 2016

Assuming they are actually numbers, without the "$" symbols, you can use this code as the custom calculation script of your field:

var plan = Number(this.getField("PlanBenefit01").value);

if (plan==100) event.value = "XXX";

else if (plan==125) event.value = "YYY";

else if (plan==150) event.value = "ZZZ";

else event.value = "";

Translate
Community Expert ,
Feb 02, 2016 Feb 02, 2016

Yes, it needs to be a custom calculation script. Is the value of "PlanBenefit01" a number with the currency symbol added to it through the Format settings, or does its actual value include that symbol?

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 ,
Feb 02, 2016 Feb 02, 2016

Assuming they are actually numbers, without the "$" symbols, you can use this code as the custom calculation script of your field:

var plan = Number(this.getField("PlanBenefit01").value);

if (plan==100) event.value = "XXX";

else if (plan==125) event.value = "YYY";

else if (plan==150) event.value = "ZZZ";

else event.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
New Here ,
Feb 09, 2016 Feb 09, 2016

Hi again.

Figured I would reach out to you since you've been the go to guy thus far.

Below is a sample of what I'm using in one of my fields:

var plan = Number(this.getField("OPPAOption1").value);

if (plan==100) event.value = "\$100";

else if (plan==125) event.value = "\$125";

else if (plan==150) event.value = "\$150";

else if (plan==200) event.value = "\$200";

else event.value = "";

Is it possible to alter this so that data can be manually entered as well?

Thanks again!

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 ,
Feb 09, 2016 Feb 09, 2016

It's possible, but it's a bit tricky. It would require moving the code from the custom calculation script of this field to the custom validation script of the other one (OPPAOption1, in this case), and adjusting it a bit.

Also, you should remove the back-slash before the dollar symbol in your code.

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 ,
Feb 10, 2016 Feb 10, 2016

Thanks.

I thought I needed the "\" in order to show the $ sign. I realized that as some fields have either dollar value or text responses I couldn't use the formatting option as I received an error message on those fields.

Any guidance on how to go about changing the script to function properly so that either a default value is given based on one of the 4 pre-determined options or give the user an option to manually enter data?

Thanks again!

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 ,
Feb 11, 2016 Feb 11, 2016
LATEST

Just want to let you know that I figured it out.

var ro = true;

var plan = Number(this.getField("fieldValueName").value);

if (plan==100)

  event.value = "WWW";

else if (plan==125)

  event.value = "XXX";

else if (plan==150)

  event.value = "YYY";

else if (plan==200)

  event.value = "ZZZ";

else {

  event.value = "";

  ro = false;

}

event.target.readonly = ro;

Works like a charm.

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 ,
Feb 04, 2016 Feb 04, 2016

Thank you yet again!

Yes, originally the text entered as the dollar symbol but I could sense where you were going with that so I changed that field to be formatted. No when the user enters the number it populates the correct amount.

Thanks again!

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