Skip to main content
MaxRosenthal
Participating Frequently
August 6, 2026
Answered

Result field is always filling minimum value even if source field is empty

  • August 6, 2026
  • 3 replies
  • 24 views

Hi, I have two fields in my script. The source field is EVPI which is a user input with auto formatting applied and the resulting event field where this custom script is entered. All of the basic conditional arithmetic is working.

When the source field is empty, the result field is supposed to be empty as well and allow for user input. However, the result field is always filled with the minimum value called in the script despite other conditionals trying to create the event value as empty. I’m not sure how the event.value is stuck at the minimum value of 100 even though it updates higher for the conditional math.

 

var EVPI = this.getField("ESTIMATED VALUE OF PUBLIC IMPROVEMENTS").value;

 

if (EVPI <= 5000) {

var Fee = 0.05*EVPI;

var FM = 100;

    if (Fee <= FM) {

    event.value = FM;

    } else if (Fee > FM) {

    event.value = Fee;

    } else {

    event.value = "";

    }

} else if (EVPI > 5000 && EVPI <= 25000) {

event.value = 250+0.04*(EVPI-5000);

} else if (EVPI > 25000 && EVPI <=100000) {

event.value = 1050+0.03*(EVPI-25000);

} else if (EVPI > 100000) {

event.value = 3300+0.02*(EVPI-100000);

} else if (EVPI === "") {

event.rc = true;

} else {

event.value = "";

}

    Correct answer Amal Jaiswal

    ​Hi @MaxRosenthal ,

    Hope you're doing well, and thanks for reaching out.

    This isn't an Acrobat bug, it's how JavaScript compares an empty string to a number.

    Here's what's happening: when EVPI is empty, this.getField(...).value returns the empty string "", not null or 0. Your very first check is:

    if (EVPI <= 5000) {

    JavaScript coerces "" to for this kind of numeric comparison, so "" <= 5000 evaluates to true. That means an empty source field always falls into your first branch, Fee becomes 0.05 * 0 = 0, and since 0 <= FM (100), event.value gets set to 100, your minimum. Your later check for EVPI === "" never actually runs, because the first if already caught it.

    The fix is to test for the empty case before you do any numeric comparisons at all

    Moving the EVPI === "" check to the top means it short-circuits before the empty string ever gets treated as a number.

    One side note, not the cause of this bug but worth knowing: event.rc is meant for Validate events (it tells Acrobat whether to accept or reject the entered value), not Calculate events where you're setting event.value. If this script is sitting in the field's Calculate tab, that event.rc = true line doesn't do anything useful there.

    Something like:

    var EVPI = this.getField("ESTIMATED VALUE OF PUBLIC IMPROVEMENTS").value;

    if (EVPI === "") {
        event.value = "";
    } else if (EVPI <= 5000) {
        var Fee = 0.05 EVPI;
        var FM = 100;
        if (Fee <= FM) {
            event.value = FM;
        } else {
            event.value = Fee;
        }
    } else if (EVPI > 5000 && EVPI <= 25000) {
        event.value = 250 + 0.04
    (EVPI - 5000);
    } else if (EVPI > 25000 && EVPI <= 100000) {
        event.value = 1050 + 0.03 (EVPI - 25000);
    } else if (EVPI > 100000) {
        event.value = 3300 + 0.02
    (EVPI - 100000);
    } else {
        event.value = "";
    }

     

    Note: I'm not a JavaScript developer, the explanation and fix are based on my research into how Acrobat's form scripting handles this, not hands-on coding experience. Worth testing carefully before relying on it in a live form.  

    Hope this will work.


    ~Amal

    3 replies

    Amal Jaiswal
    Community Manager
    Amal JaiswalCommunity ManagerCorrect answer
    Community Manager
    August 6, 2026

    ​Hi @MaxRosenthal ,

    Hope you're doing well, and thanks for reaching out.

    This isn't an Acrobat bug, it's how JavaScript compares an empty string to a number.

    Here's what's happening: when EVPI is empty, this.getField(...).value returns the empty string "", not null or 0. Your very first check is:

    if (EVPI <= 5000) {

    JavaScript coerces "" to for this kind of numeric comparison, so "" <= 5000 evaluates to true. That means an empty source field always falls into your first branch, Fee becomes 0.05 * 0 = 0, and since 0 <= FM (100), event.value gets set to 100, your minimum. Your later check for EVPI === "" never actually runs, because the first if already caught it.

    The fix is to test for the empty case before you do any numeric comparisons at all

    Moving the EVPI === "" check to the top means it short-circuits before the empty string ever gets treated as a number.

    One side note, not the cause of this bug but worth knowing: event.rc is meant for Validate events (it tells Acrobat whether to accept or reject the entered value), not Calculate events where you're setting event.value. If this script is sitting in the field's Calculate tab, that event.rc = true line doesn't do anything useful there.

    Something like:

    var EVPI = this.getField("ESTIMATED VALUE OF PUBLIC IMPROVEMENTS").value;

    if (EVPI === "") {
        event.value = "";
    } else if (EVPI <= 5000) {
        var Fee = 0.05 EVPI;
        var FM = 100;
        if (Fee <= FM) {
            event.value = FM;
        } else {
            event.value = Fee;
        }
    } else if (EVPI > 5000 && EVPI <= 25000) {
        event.value = 250 + 0.04
    (EVPI - 5000);
    } else if (EVPI > 25000 && EVPI <= 100000) {
        event.value = 1050 + 0.03 (EVPI - 25000);
    } else if (EVPI > 100000) {
        event.value = 3300 + 0.02
    (EVPI - 100000);
    } else {
        event.value = "";
    }

     

    Note: I'm not a JavaScript developer, the explanation and fix are based on my research into how Acrobat's form scripting handles this, not hands-on coding experience. Worth testing carefully before relying on it in a live form.  

    Hope this will work.


    ~Amal

    MaxRosenthal
    Participating Frequently
    August 6, 2026

    Ah that makes sense <= 5000 also includes 0. Thank you again Amal haha.

     

    I’ve been using event.rc = true; to allow user input when other conditions aren’t met. It’s worked in a handful of other field calcs. I’m not sure if there is a better way, but it makes the form work how it needs to. 

    Right now I changed

    if (EVPI === "") {
        event.value = "";
    }

    to

    if (EVPI === "") {
        event.rc = true;
    }

    And it seems to function. If this stops for some reason I’ll switch it back as user input is not critical for this field since all the math is done.

    Amal Jaiswal
    Community Manager
    Community Manager
    August 6, 2026

    Hi there,

    We are glad to hear that it worked 😊 Feel free to contact us for any future assistance.

    ~Amal