3 Replies Latest reply on Jul 10, 2011 1:00 PM by gkaiseril

    Calculation Script to change a number based on quantity in another

    ZiggyZigZ

      Hello - and thanks for the help - I have no real idea of what I am doing when it comes to writing script.  I would like the cost of something to change depending on the quantity ordered... ie. the more you buy the better price you get.

       

      (ie.  5 or less = $18.00, 6-10 = $17.00, 11+ = $16.00)

       

      How do I write a calc script to accomplish this?  Also, if the "Quantity" affecting the outcome is a result of a calculation itself will the code still work?

       

      I have uploaded a sample to the following:

       

      http://www.shupaca.com/Calc.html

       

      Thanks!

        • 1. Re: Calculation Script to change a number based on quantity in another
          gkaiseril MVP & Adobe Community Professional

          Check the spelling of you field names with in your custom scripts.

           

          Some overall observations:

           

          Use the provided formats for fields unless you want to write your own format code,  validation code, or keystrokes code.

           

          Use the default value option to set default values of fields, so if the form is reset, the default value is restored. You can also access this value in code.

           

          Use the 'read only' parameter to lock field you do not want users of the form to update.

           

          Check the JavaScript console for errors. You misspelled the field name.

           

          Do not use a calculation event when another type of event can perform the same script,. Calculation order can become a problem. All field calculations are rerun when ever any field that is used in a calculation is updated, so by the end of your form you may have a significant amount recalculation of unnecessary calculations being performed.

           

          Setting the 'Scarf Cost' field to read only, default value of 18, and a 'Number' format with 2 decimal places and the "$" currency symbol and removing all scripts for this field, one could use the following "On Blur' action for the 'Scarf Quantity' field:

           

          var oPrice = this.getField('Scarf Cost');
          oPrice.value = oPrice.defaultValue;
          if (event.value > 5) {
          oPrice.value = 16;
          }

          • 2. Re: Calculation Script to change a number based on quantity in another
            ZiggyZigZ Level 1

            Thanks for the help.  I still am not getting it to work though... How to i

            get the script to know that the (event.value) refers to the 'Scarf Quantity'

            field? I also don't have a default value option in the text filed

            properties.  How might I code it?

             

            Thanks!

            • 3. Re: Calculation Script to change a number based on quantity in another
              gkaiseril MVP & Adobe Community Professional

              The 'event' is the event for the field in which the script resides.

               

              For the field's 'properties' look on the 'Options' tab for the appropriate entry location.