Copy link to clipboard
Copied
Hi! I need to convert the following excel formula to Javascript for my PDF, I've studied basic syntax a bit, but cant seem to figure it out.
The excel formula is:
=IF(A15=1,B15*0.75,(A15-0.5)*B15)
However, in the PDF, A15 will be Days1 and B15 will be MIE1 .
Please Help
The custom calculate script for the field could be:
(function () {
// Get the values from the input fields, as numbers
var nDays1 = +getField("Days1").value;
var nMIE1 = +getField("MIE1").value;
// Calculate and set this field's value
event.value = nDays1 == 1 ? 0.75 * nMIE1 : (nDays1 - 0.5) * nMIE1;
})();
That last line is equivalent to:
if (nDays == 1) {
event.value = 0.75 * nMIE1;
} else {
event.value = (nDays1 - 0.5) * nMIE1;
}
Copy link to clipboard
Copied
The custom calculate script for the field could be:
(function () {
// Get the values from the input fields, as numbers
var nDays1 = +getField("Days1").value;
var nMIE1 = +getField("MIE1").value;
// Calculate and set this field's value
event.value = nDays1 == 1 ? 0.75 * nMIE1 : (nDays1 - 0.5) * nMIE1;
})();
That last line is equivalent to:
if (nDays == 1) {
event.value = 0.75 * nMIE1;
} else {
event.value = (nDays1 - 0.5) * nMIE1;
}