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

Converting excel formula into adobe form?

New Here ,
Jul 10, 2018 Jul 10, 2018

I'm trying to convert a somewhat complicated excel formula into javascript (I guess?) for use on a PDF form. The formula in excel is:

=MIN(IF(B3<30000,(B3/12*0.6667),IF(AND(B3>30000,B3<80004),1667+(((B3/12)-2500)*0.575),(((B3/12)-6667)*0.45)+4063)),6000)

On the PDF, B3 will refer to a form field that is labelled Annual Income.

Help????

Thank you!!!!

TOPICS
PDF forms
1.2K
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
1 ACCEPTED SOLUTION
LEGEND ,
Jul 10, 2018 Jul 10, 2018
LATEST

I suspect that formula may not cover the case of B3 being equal to 30,000 correctly.

Here's a sample custom calculation script that is written in an attempt to make the logic clear:

// Get the field value of the Annual Income field, as a number

var B3 = +getField("Annual Income").value;

// Variable for intermediate value

var num;

// Calculate the intermediate value

if (B3 < 30000)  {

    num = B3 / 12 * 0.6667;

} else if (B3 < 80004) {

    num = 1667 + (B3 / 12 - 2500) * 0.575;

} else {

    // B3 >= 80004

    num = 4063 + (B3 / 12 - 6667) * 0.45;

}

// Set this field to the minimum of the intermediate value and 6000

event.value = Math.min(num, 6000);

View solution in original post

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 ,
Jul 10, 2018 Jul 10, 2018

You should study the basic syntax of JavaScript and you'll find all the equivalents of these functions.

MIN -> Math.min()

IF -> if () {} else {}

AND -> &&

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 ,
Jul 10, 2018 Jul 10, 2018

I'm working on understanding javascript...so using your advice would it be:

Math.min(if("annual income" < 30000 {"annual income"/12*0.6667}IF(&&("annual income">30000,"annual income"<80004),1667+((("annual income"/12)-2500)*0.575),((("annual income"/12)-6667)*0.45)+4063)),6000)

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 ,
Jul 10, 2018 Jul 10, 2018

No, not at all, it's not a simple search&replace task. You have to use the correct syntax for JavaScript.

Also, you need to learn how to access the values of form fields in a PDF and how to apply a new value to them.

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 ,
Jul 10, 2018 Jul 10, 2018
LATEST

I suspect that formula may not cover the case of B3 being equal to 30,000 correctly.

Here's a sample custom calculation script that is written in an attempt to make the logic clear:

// Get the field value of the Annual Income field, as a number

var B3 = +getField("Annual Income").value;

// Variable for intermediate value

var num;

// Calculate the intermediate value

if (B3 < 30000)  {

    num = B3 / 12 * 0.6667;

} else if (B3 < 80004) {

    num = 1667 + (B3 / 12 - 2500) * 0.575;

} else {

    // B3 >= 80004

    num = 4063 + (B3 / 12 - 6667) * 0.45;

}

// Set this field to the minimum of the intermediate value and 6000

event.value = Math.min(num, 6000);

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