13 Replies Latest reply on Jul 25, 2011 9:12 PM by George_Johnson

    Conditional Scripting for Fillable PDF Form

    TSmith1200

      I will start off by saying that I am a communications professional who has NO experience in Java Scrpting. Currently, I am orking on creating a fillable PDF form that will be used internally. There are two variable dollar amounts that need to be populated based on information that is entered into another field.

       

      More specifically, years of service completed determines the cost that a retired employee is required to pay for Single or Two Party health care coverage. For example, if 10 years of service is selected, then the Single coverage line item needs to populate with $598.16 and the Two Party line item needs to populate with $1,196.30. Can a drop-down menu be used for years of service and still have the variable amounts display or would it need to be a text field where a value is entered?

       

      There are 21 different years of sevice categories with two dollar amounts assigned to each. From the research I've done it appears that a custom calculation using Java Script needs to be developed to make the form function as outlined above.

       

      Any insight into how the scripting needs to be set up would me much appreciated!

        • 1. Re: Conditional Scripting for Fillable PDF Form
          try67 MVP & Adobe Community Professional

          You can use a drop-down. Set the export values to the single year price (so

          in the case of 10 years, set the export value to be 1,196.30). You can then

          create a text field that shows the price for a Single coverage, being

          identical to the value of the drop-down, and another for the Two coverage,

          being double that. You can do it without any custom-made scripts that way.

          • 2. Re: Conditional Scripting for Fillable PDF Form
            TSmith1200 Level 1

            Thanks so much for the information! I was able to get the Single cost to display correctly. However, I can't figure out how I would get the Two Party cost to be double the Single cost. I placed a text field in the appropriate place, but I don't know how to get the calculation to work.

             

            Also, is there a way to account for rounding? The dollar values are not rounded consistently (some rounded up and some rounded down).

             

            Any insight would be much appreciated!

            • 3. Re: Conditional Scripting for Fillable PDF Form
              gkaiseril MVP & Adobe Community Professional

              You need to look at the values with more decimal places showing to see what is going on.

               

              The displayed values are rounded, but the results in that displayed field are not rounded so if those values are used elsewhere in a calculation the unrounded value is used.

              • 4. Re: Conditional Scripting for Fillable PDF Form
                try67 MVP & Adobe Community Professional

                You display the single cost times 2, use the Simple Notation Calculation

                option, and enter

                2 * SingleCost (or whatever is the name of that field, but be aware it can't

                have spaces or special characters in the name)

                • 5. Re: Conditional Scripting for Fillable PDF Form
                  TSmith1200 Level 1

                  Is there a way to account for inconsistencies in rounding? For example, one of the service milestones has a Single cost of $578.22, but the Two Party cost is $1,156.42 (two pennies less than 2x the Single cost).

                   

                  The amounts I need to display on the form are exact figures that were provided to me. I don't have the extra decimal places in the value to manipulate.

                  • 6. Re: Conditional Scripting for Fillable PDF Form
                    try67 MVP & Adobe Community Professional

                    Not really. You will need a more complex script to account for that, with all of the prices hard-coded into it.

                    • 7. Re: Conditional Scripting for Fillable PDF Form
                      TSmith1200 Level 1

                      Any ideas on where I can find more information or ideas on scripting? I have no experience with Java at all (other than the kind you drink).

                      • 8. Re: Conditional Scripting for Fillable PDF Form
                        gkaiseril MVP & Adobe Community Professional

                        > Is there a way to account for inconsistencies in rounding? For example, one of the service milestones has a Single cost of $578.22, but the Two Party cost is $1,156.42 (two pennies less than 2x the Single cost).

                         

                        Please explain what you mean by inconsistencies in rounding?

                         

                        JavaScript uses the 5/4 rounding. Your example is not an example of a rounding error within JavaScript, but your assumption about how the rates are computed.  The rates maybe based on a  schedule of charges or there is a discount value within the calculation of the rates.

                         

                        You can download the Acrobat JavaScript documentation form Adobe for free.

                         

                        And there is an error when using the Math.round function to round numbers of certain values, but it does not appear very often and there is a known solution for the problem.

                        • 9. Re: Conditional Scripting for Fillable PDF Form
                          TSmith1200 Level 1

                          The form that I have created needs to display the cost for health care benefits for two different coverage levels. Both costs are driven by the years of service an employee has completed. Ideally, I want the applicable costs to be displayed once the years of service are selected.

                           

                          For example, I select 10 years from a drop-down menu or type in 10 years of service and X value for Single coverage populates and Y value for Two Party coverage populates.

                           

                          It was originally suggested that I create a drop-down menu for years of service and set the export value for each category to the Single cost. The cost for Two Party coverage would then be calculated as two times the Single rate using a simple formula.

                           

                          As I reviewed the costs that were provided to me more closely, I noticed that some values were not exactly two times the Single rate. The Two Party cost was sometimes a penny or two higher or lower than the value that needed to be displayed. That's what I meant by inconsistencies in rounding. The differences lie in the actual values that were given to me, not anything that was calculated.

                           

                          I am thinking I need to come up with some conditional statement programming so that if years of service = X, then Y is the Single cost and Z is the Two Party cost. I have no experience with Java scripting so I don't even know where to start with writing the formula.

                           

                          Any insight would be much appreciated.

                          • 10. Re: Conditional Scripting for Fillable PDF Form
                            gkaiseril MVP & Adobe Community Professional

                            If he values of plan selected are not duplicated, you can set the optional value of the dropdown box.

                             

                            Because of the number of possible options, you might want to consider multiple dropdown boxes or otter types of form fields to set the criteria for the plan selection. You need to clearly identify the plans and selection criteria for the pricing. It is all possible using just drop down boxes, but the code is tricky.

                             

                            Programming List and Combo fields in Acrobat and LiveCycle forms - Part 1

                             

                            It appears you could use 2 different arrays. One for single and the other for the two ;party. Then each array element would be the ;price for a tenure element.

                             

                            You cold also created a nested if statement for the decision.

                            Or I would look at the switch statement for assigning the price.

                             

                            But first you really need to very clearly define you problem and not guess at what you want and guess at the values you are trying to arrive at.

                            • 11. Re: Conditional Scripting for Fillable PDF Form
                              George_Johnson MVP & Adobe Community Professional

                              It looks like there will always be two prices associated with each item in the combo box, so you can include both as the export value of each item, separated by a delimiter. As an example, if you set the export value to "78.42|138.78", the custom Keystroke script for the combo box could look something like:

                               

                              // Custom Keystroke script for combo box
                              (function () {
                              
                                  if (!event.willCommit) {
                              
                                      // Get the export value of the selected item
                                      var ev = event.changeEx;
                              
                                      // Get the two values, which are separated by the pipe character, into an array
                                      var aVals = ev.split("|");
                              
                                      // Place the values into the fields
                                      getField("amount1").value = aVals[0];
                                      getField("amount2").value = aVals[1];
                              
                                  }
                              
                              })();
                              

                               

                              where "amount1" and "amount2" are the names of the two text fields that display the prices corresponding to the selection. This code assumes the "commit selected value immediately" property is selected for the combo box.

                               

                              Edit: corrected typo

                              • 12. Re: Conditional Scripting for Fillable PDF Form
                                JBinReno

                                Sorry to butt in on your discussion, but I've been trying to find the, "You can download the Acrobat JavaScript documentation form Adobe for free" documentation on Adobe's website, but have been unsuccessful. Anyone have a link to where I can find it, please?

                                • 13. Re: Conditional Scripting for Fillable PDF Form
                                  George_Johnson MVP & Adobe Community Professional

                                  The latest version is included in the Acrobat SDK as a PDF. The link is unavailable at the time I posted this, but if you Google "Acrobat SDK" you'll find it. You'll also find previous some previous versions and the online version here: http://www.adobe.com/devnet/acrobat/javascript.html