3 Replies Latest reply on Mar 14, 2014 12:58 PM by try67

    New to Scripting- need help with a calc field driven off of radio button & value of another field

    GSRG

      Hello,

       

      I'm new to JavaScripting.  Working in Adobe Acrobat X Pro.  I have a form with two radio buttons "Seller Pays" and "Split Cost".  If "Seller Pays" is clicked, then another form field "Escrow Fee" that will contain a dollar amount based on the amount in a third field, "Price".  The amount in "EscrowFee" will be based on a combination of if/then statements, i.e., If "Price" <=to 100000, then "EscrowFee" is 500......if "Price" is >101000 but <150000, then EscrowFee is 550....etc.etc.  If the "SplitCost" button is clicked, then the figures will be the same as the other button, but split in half.  Been struggling with this trying different ideas for two days.  Any help / ideas would be appreciated.

        • 1. Re: New to Scripting- need help with a calc field driven off of radio button & value of another field
          try67 MVP & Adobe Community Professional

          You should do this as the custom calculation script of the EscrowFee field. Something like this...

           

          var cost = this.getField("Cost Type").value; // this should be the radio-button group

          if (cost=="Off") event.value = ""; // if no radio-button is selected, leave the field empty

          else {

              var fee = 0;

              var price = Number(this.getField("Price").value);

              if (price<=100000)

                  fee = 500;

              else if (price>101000 && price<150000)

                  fee = 550;

              // etc.

           

              if (cost=="Split Cost") // split the fee by 2 if "Split Cost" is selected

                  fee = fee / 2;

           

              event.value = fee;

          }

          • 2. Re: New to Scripting- need help with a calc field driven off of radio button & value of another field
            GSRG Level 1

            Thank you Gilad D.  This got me on the right track, but still having issues.  So to clarify my goal...

            I've got a Radio group with 4 radio buttons (the group & each individual button are all named "Escrow"). Buttons are for: Buyer Pays, Seller Pays, Split Cost, or N/A.  If Buyer Pays or if N/A, I want the Fee referenced for Escrow Fee to be $0.00.  But if Seller Pays or Split Cost is clicked, I want the calculation to run based on the "if/else" statements you provided. I modified your "if" statement to account for an amount equal to zero - otherwise it popped the minimum fee into the field.  My problem is that I don't have anything in the code that distinguishes one radio button in the group from another.  So, how would the program know that the 1st or 4th button were clicked, which would result in a $0.00 cost, as opposed to the 2nd or 3rd button which would result in either 100% or 50% of the cost.  Also, since I couldn't figure out how to distinguish between the Seller Pay and Split cost buttons from the same radio button group, I have not yet included the code you provided for Split Cost.  Also, it doesn't matter which button I click, it will populate the Escrow Fee based on the Purchase Price, even if the button is Buyer Pays or N/A.


            The code that I am currently using (thanks to you) is as follows:

             

            var cost = this.getField("Escrow").value; // this should be the radio-button group

            if (cost=="Off") event.value = ""; // if no radio-button is selected, leave the field empty

            else {

                var fee = 0;

             

                var price = Number(this.getField("PurchasePrice").value);

             

                if (price>0  &&  price<=100000)

                    fee = 500;

             

                else if (price>101000 && price<150000)

                    fee = 550;

             

                // etc.


                event.value = fee;

            }

             

            Again thanks for your help.  Hoping you can at least guide me in the right direction.

            • 3. Re: New to Scripting- need help with a calc field driven off of radio button & value of another field
              try67 MVP & Adobe Community Professional

              The value of a radio-button group is either "Off", when nothing is selected, or the "Radio button choice" value of the selected item in that group.