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

Help converting a basic Excel-style formula into JavaScript

Community Beginner ,
May 27, 2016 May 27, 2016

I have a self populating table in an Acrobat document; figured out most of the simple equations but I have one slightly more complicated one that needs JavaScript and I know nada.

The reader inputs two values (a), (b)

and if I were to write the fomula in Excel I would write:

=a-(IF(b<20.5,b,20.5))+41.5

Any thoughts on how to translate this?  Thanks!

TOPICS
Acrobat SDK and JavaScript
528
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

LEGEND , May 27, 2016 May 27, 2016

If you want this to be a custom calculation script for a field, it could be:

// Custom calculation script for text field

(function () {

    // Get the field values, as numbers

    var a = +getField("A").value;

    var b = +getField("B").value;

    // Set this field's value

    event.value = a - (b < 20.5 ? b : 20.5) + 41.5;

})();

but replace "A" and "B" in the getField statements with the actual field names you're using.

Translate
LEGEND ,
May 27, 2016 May 27, 2016

If you want this to be a custom calculation script for a field, it could be:

// Custom calculation script for text field

(function () {

    // Get the field values, as numbers

    var a = +getField("A").value;

    var b = +getField("B").value;

    // Set this field's value

    event.value = a - (b < 20.5 ? b : 20.5) + 41.5;

})();

but replace "A" and "B" in the getField statements with the actual field names you're using.

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 Beginner ,
May 27, 2016 May 27, 2016
LATEST

Yes!  That did it!  I was close a couple of times earlier today, but didn't include the " ; "

Thank you!

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