5 Replies Latest reply on Nov 17, 2009 11:54 AM by gkaiseril

    Javascript look up scripting help

    chriscaines84

      Hi

       

      I'm using Adobe Acrobat 9 Professional trying to create a form, and need some help with some scripting.  I've tried to edit a few javascripts people have posted, but seem to be getting errors all over the place.

       

      I have a set of parameters, resulting in an associated cost:

       

      Parameter 1 - Less than 500 = Value 1 (£5.00)

      Parameter 2 - Between 501 to 1000 = Value 2 (£4.75)

      Parameter 3 - Between 1001 to 1500 = Value 3 (£4.50)

      Parameter 4 - Greater than 1500 = Value 4 (£4.00)

       

      I need the form to do the following:

      - Look up a value in my form

      - Check which category it falls in, i.e. if the value is 495 it lies within Parameter 1 thus equals Value 1

      - Show which value associated - in this case £5.00 - showing this monetary value

       

      It might sound simple, but seeing I don't really get javascript, so I'm struggling!

       

      Can anyone help?

       

       

      Thanks

       

      Chris

        • 1. Re: Javascript look up scripting help
          gkaiseril MVP & Adobe Community Professional

          Do you have any programing experience, and not Excel macros?

           

           

          What scripts and what errors?

           

           

          JavaScirpt is object orientated, so one references an object and a property of method of that object or a variable.

           

           

          It appears you are trying determine a value based on a given quantity. So you can use an 'if' statement or 'select' statement.

           

           

          Since you have not provided enough detail about where the value you want evaluated comes from, I must assume it is a field with a name. I'll use the name 'quantity' for the field name. Comments start with '//'

           

           


          // custom calculation script using 'if'  statement
          // compute the shipping cost from the quantity field
          // get the value of the quantity field
          var fQuantity = this.getField('quantity').value;
          // set event value property bases on value of quantity
          // default value is 5
          event.value = 5;
          // determine the rate from the quantity value
          if(fQuantity > 1500) event.value = 4;
          else if(fQuantity > 1000) event.value = 4.5;
          else if(fQuantity > 500) event.value = 4.75;

           

          // custom calculation script using 'switch' statement
          // compute the shipping cost from the quantity field
          var fQuantity = this.getField('quantity').value;
          // set event value property bases on value of quantity
          // determine the rate from the quantity value
          switch(true) {
          case (fQuantity > 1500):
            event.value = 4;
          break;
          case (fQuantity > 1000):
            event.value = 4.5;
          break;
          case (fQuantity > 500):
            event.value = 4.75;
          break;
          default:
            event.value = 5;
          break;
          } // end switch

           

          1 person found this helpful
          • 2. Re: Javascript look up scripting help
            chriscaines84 Level 1

            Not a lot of experience of coding at all - glorified HTML, CSS, just the basics... muddle through :S

             

            I've attached an example form with the data range I need the form to look up.  Tried you're suggestion and I'm not sure how to get it to work - I've changed the Quantity tag to match the field.

             

            Any ideas?

             

            Really appreciate your help.

             

             

            Chris

             

            #####################################################################################

             

            Disclaimer

             

            Nothing in this E-mail is to be interpreted as agreement on behalf

            of Pinewood Technologies Plc to enter into any legally binding

            agreement unless the recipient has received confirmation in writing

            from a director of the business that the sender is so authorised.

             

            If you have received this E-mail in error please forward it to

            email-returns@pinewood.co.uk, destroy and delete it and do

            not rely upon it in any way.

             

            Publication and/or distribution of it is strictly prohibited and may be

            unlawful.

             

            • 3. Re: Javascript look up scripting help
              gkaiseril MVP & Adobe Community Professional

              Check you post, there is no attachment visible in the post and the attachment has been stripped from your email.

              • 4. Re: Javascript look up scripting help
                chriscaines84 Level 1

                Sorry, re-attached

                • 5. Re: Javascript look up scripting help
                  gkaiseril MVP & Adobe Community Professional

                  I provided 2 different scripts for the calculation, you only needed to use one of them.

                   

                  I see you did not change the field name 'quantity' to 'checks_req_calc'.

                   

                  Now if you want to use the values from the array of quantities and values, you could change the script to calculate the field name based on the quantity to the row for the value.

                   

                  // custom calculation script using 'if' statement
                  // compute the shipping cost from the quantity field
                  var fQuantity = this.getField('checks_req_calc').value;
                  // set event value property bases on value of quantity
                  var fPriceRow = 1;
                  // determine the rate from the quantity value
                  if(fQuantity > 1500) fPriceRow = 4;
                  else if(fQuantity > 1000) fPriceRow = 3;
                  else if(fQuantity > 500) fPriceRow = 2;
                  // using the price row number - get the value of that field
                  //  field name is 'value_#' where # is 1 - 4 depending upon the number of checks ordered
                  event.value = this.getField('value_' + fPriceRow).value;