Copy link to clipboard
Copied
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!!!!
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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 -> &&
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more