Skip to main content
Participating Frequently
January 19, 2016
Answered

If/Then Converted to a Custom Calculation Script

  • January 19, 2016
  • 2 replies
  • 610 views

Can anyone help me convert =IF(A2-A1>0, 0, A2-A1) into a Custom Calculation Script for use in an Adobe form?

Thank you!

This topic has been closed for replies.
Correct answer George_Johnson

If A1 and A2 are field names, then the custom calculation script could look like:

(function () {

    // Get the field values, as numbers

    var A1 = +getField("A1").value;

    var A2 = +getField("A2").value;

    // Set this field's value

    event.value = A2 - A1 > 0 ? 0 : A2 - A1;

})();

2 replies

George_JohnsonCorrect answer
Inspiring
January 21, 2016

If A1 and A2 are field names, then the custom calculation script could look like:

(function () {

    // Get the field values, as numbers

    var A1 = +getField("A1").value;

    var A2 = +getField("A2").value;

    // Set this field's value

    event.value = A2 - A1 > 0 ? 0 : A2 - A1;

})();

lev_savranskiy
Participating Frequently
January 21, 2016

event.value = A2-A1>0 ? 0 : A2-A1;