4 Replies Latest reply on Jan 24, 2012 2:34 AM by spyderbait

    unknown script command

    spyderbait

      Hi there,

       

      Im new to java scripting but for my role playing group im creating interactive pdf forms for them to use but ive got to a place where im trying to use acrobat X pro to calcute three values. At the moment i can calculate the three values but is there a way i can only get the total value to calculate only if a certain field is filled in. I have fifty fields to do this calculation on but they are set up in exactly the same way so i will use 'VALUE' as a generic term for the different fields

       

       

      the caculation i need is

       

      VALUE A = VALUE B + VALUE C + VALUE D

       

      but VALUE A should read 0 if VALUE C is left blank

       

      thankyou any response will be appreciated

        • 1. Re: unknown script command
          gkaiseril MVP & Adobe Community Professional

          It is not clear what program, Acrobat or LiveCycle Designer, you are using. It is also not clear where you are entering your script.

           

          Please provide more details.

           

          If you are trying to control the execution of a script,then you need to use an 'if' control statement. This statement is supported by Acrobat JavaScript, LiveCycle Designer FormCalc, and LiveCycle Designer JavaScript. It is not supported by Acrobat's simplified field notation nor Acrobat's 'Field is the ___ of the following fields' option.

          • 2. Re: unknown script command
            spyderbait Level 1

            thankyou GKaiseril and i amsorry its adobe acrobat X profesional

             

            im using the form editor and within that im going through theproperties screen using the calculate tab of VALUE A the script i used above is not the script im was using it was the easiest way to illustrate what i am trying to achive if i could please have an example script that would be appreciated

            • 3. Re: unknown script command
              George_Johnson MVP & Adobe Community Professional

              The custom calculate script for the  A field should look something like:

               

              // Get the field values
              var b = +getField("B").value;
              var c = getField("C").valueAsString;
              var d = +getField("D").value;
              
              // Sum the values if c is not blank
              // and set the result to the sum
              event.value = c ? b + +c + d : 0;
              

               

              The variable "c" will be a string, so I used the unary + operator to convert it to a number, which I also did to the values of the other fields. This ensures numerical addition as opposed to string concatenation if any of the fields are empty.

               

              That last line of code is equivalent to:

               

               

              if (c) {
                  event.value = b + +c + d;
              } else {
                  event.value = 0;
              }
              

               

              And that first line of code means: "if the string in the c variable is something other than an empty string..."

              • 4. Re: unknown script command
                spyderbait Level 1

                thankyou George Johnson

                 

                exactly what i needed i can complete the form now works perfectly