4 Replies Latest reply on Feb 12, 2013 7:41 AM by Kayle Simon

    I need a conditional execution for state sales tax.

    Kayle Simon

      My client does work in three states. We have a 3 checkboxes next to "TAX" on their form, named DC, MD, VA, and we'd like the field, "Subtotal" to be muliplied by 6% for when MD or  DC has been checked, and by 0% when VA has been checked, with the results going into the Sales Tax field. I saw some ideas for making the Sales Tax field a drop down menu with different events, but I had two problems with that: one I couldn't get it it work, but 2, sometimes our form is handled on paper and having check boxes in that area, rather than beside it, is a pain.

       

      I was hoping someone somewhere had this need already but I can find no forum items that give me the javascript juice for this one.

        • 1. Re: I need a conditional execution for state sales tax.
          George_Johnson MVP & Adobe Community Professional

          Set up three check boxes with the same name. For the VA one, set the export value to 0. For the other two, set the export values to 0.06 and 0.060, respectively. When used as a number, the last two values will be the same but it will allow the check boxes to be independent so that checking one does not check the other. Then in the field that calculates the amount of tax, you'd just multimply the value of the check box field by the subtotal. SOmething like:

           

          // Custom calculate script for text field

          (function () {

           

              // Get the value of the check box

              var v = getField("state").value;

           

              // Blank this field if no check boxes are selected

              if (v === "Off") {

                  event.value = "";

              } else {

                  // Calculate the tax, rounding to the nearest cent

                  event.value = util.printf("%.2f", getField("subtotal").value * v);

              }

           

          })();

           

          where "state" is the name of the state check boxes. This type of rounding is normally correct, but doublecheck to make sure it's not something like always round up to the nearest cent.

          • 2. Re: I need a conditional execution for state sales tax.
            Kayle Simon Level 1

            Thanks for giving it a shot, but it didn't quite work.

             

            I added three text boxes, called them all state1 (i already had a state field on my form) and added your script with state1 in place of state into my tax field where i want the results.

             

            Nothing happens inside the Tax field when I click on the boxes.

             

            I'd much prefer to call them MD, DC and VA if that is possible...but mostly I just need to figure out a way to make it work. Any help much appreciated.

            • 3. Re: I need a conditional execution for state sales tax.
              George_Johnson MVP & Adobe Community Professional

              You said text fields, but you set up check boxes, correct? And did you set the export values correctly? If you're stuck, I'd be happy to take a look at the form if you're free to email it to me: acroscript at gmail dot com

              • 4. Re: I need a conditional execution for state sales tax.
                Kayle Simon Level 1

                Here's what I did: Open file in acrobat, open tools, edit form. Add new field: checkbox. Field name: state1. Required field is not checked. In properties, export value is .06. Made a copy of that box but changed the export value to 0. (Ultimately I'll have to add text to indicate the first one as Md/DC and the second one as VA.) Then in the tax box, I clicked on Calculate, and added your script to the custom script area.

                 

                I will certainly be happy to send it to you, that's very nice of you. I have also, since trying to get this to work, had a lot of acrobat crashes...maybe the form has just gotten weird somehow. It's been time consuming to create (started in InDesign) and I'm so close to finished with it, I'm a bit frustrated.