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

How do I populate field 1 with the amount from field 2 based on the description of field 3?

Guest
Dec 12, 2016 Dec 12, 2016

How do I populate field 1 with the amount from field 2 based on the description of field 3? I am new to java script and so far I have placed in the calculate tab   
if (description == “Single Life”) this.getField(amount);
Needless to say this does not work.
Any help is appreciated.

TOPICS
Acrobat SDK and JavaScript , Windows
358
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 ,
Dec 12, 2016 Dec 12, 2016

As the custom calculation script of field 1 you can use this code, for example:

if (this.getField("description").valueAsString=="Single Life") event.value = this.getField("amount").value;

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
Guest
Dec 12, 2016 Dec 12, 2016
LATEST

thank you very much - worked 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
LEGEND ,
Dec 12, 2016 Dec 12, 2016

For that to work, the custom calculation script for field 1 would have to be something like:

// Get the field values

var sDesc = getField("description").valueAsString;  // string

var nAmount = getField("amount").value;  // number

// Set this field value

if (sDesc === "Single Life") {

    event.value = nAmount;

} else {

    event.value = "";  // Blank this field

}

You can add "else if" blocks to handle other cases, or use the "switch" JavaScript statement instead, which is what I'd recommend.

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