1 Reply Latest reply on Sep 8, 2015 4:21 PM by George_Johnson

    Javascript to change form field color if value greater than 12


      Hello everyone,


      As a newbie with scripts and after spending much of the day searching for a script I can tailor to my specific situation, I am turning to this community for help. I've seen solutions to scenarios far more complex than mine, however, my inexperience is getting in the way of me correctly modifying those solutions down to fit my needs.


      I have a form I am creating in Acrobat DC, the field that I wish to apply the script to displays the sum subtotal from about 5 other fields.  The calculation is working, but if the calculated value is greater than 12, I would like the field to turn red.


      Would someone please point me in the right direction to create the script that will turn the field red if the value is greater than 12.


      Thank you in advance.



      So, after search more, I found: Changing color of calculated-read only field based on conditions

      and applied as below and it worked!!


      // Custom calculation script for Subtotal_2

      (function () {

           // Get the field values, as numbers

        var v1 = getField("Dropdown6").value;

        var v2 = getField("Dropdown7").value;

        var v3 = getField("Dropdown8").value;

        var v4 = getField("Dropdown9").value;

        var v5 = getField("Dropdown10").value;

        var v6 = getField("Dropdown11").value;

        var v7 = getField("Dropdown12").value;

        var sum = v1 + v2 + v3 + v4 + v5 + v6 + v7;

           // Set this field's value;

          event.value = sum;

           // Set this field's background color

          event.target.fillColor = sum <= 12 ? color.red : color.white;


        • 1. Re: Javascript to change form field color if value greater than 12
          George_Johnson MVP & Adobe Community Professional

          That will work if none of the input fields are blank. The comment near the top indicates it's getting the values as numbers, which is what you need to do, but the code doesn't actually ensure that. If you change those lines to this:


            var v1 = +getField("Dropdown6").value;

            var v2 = +getField("Dropdown7").value;

            var v3 = +getField("Dropdown8").value;

            var v4 = +getField("Dropdown9").value;

            var v5 = +getField("Dropdown10").value;

            var v6 = +getField("Dropdown11").value;

            var v7 = +getField("Dropdown12").value;


          there won't be a problem.