2 Replies Latest reply on Oct 7, 2008 3:54 PM by (ken_ross)

    new to acrobat, kinda... help with calculations?

      Okay, I feel ridiculous not figuring this out on my own; for crying out loud I am a programmer and designer and have been working with coding for ages; however acrobat doesn't seem to work like I think it should.

      If someone can answer this one question, I think I can figure out all of my issues, but for some reason I can't get started on it.

      I have a field named Data_Input1, another named Data_Input2, and a field named Calculated_Data. In Data_Input1 and Data_Input2, I enter any numerical value; this is set up properly. I then want Calculated Data to perform the following calculation... (the value of Data_Input1 is X and Data_Input2 is Y)

      = [ ( ( X - 10 ) / 2 ) + ( Y / 2 ) ]

      So how do I make it calculate like that?

      Thanks!
        • 1. Re: new to acrobat, kinda... help with calculations?
          George_Johnson MVP & Adobe Community Professional
          The calculation JavaScript for a field created in Acrobat (as opposed to LiveCycle Designer) could look something like:


          // Get field values, as numbers
          var v1 = +getField("Data_Input1").value;
          var v2 = +getField("Data_Input2").value;

          // Calculate and set this field's value
          event.value = (v1 - 10) / 2 + (v2 / 2);


          To prevent unnecessarily creating globals, you should really do:


          (function(){

              // Get field values, as numbers
              var v1 = +getField("Data_Input1").value;
              var v2 = +getField("Data_Input2").value;

              // Calculate and set this field's value
              event.value = (v1 - 10) / 2 + (v2 / 2);

          })();


          You could also set up a document-level function that returns the value and your calculation script would be:

          event.value = my_calculation():

          You might also want to validate your inputs. Also, if you do not have it already, you should get a hold of the Acrobat JavaScript Reference.

          George
          • 2. Re: new to acrobat, kinda... help with calculations?
            Level 1
            Thanks, that is working wonderfully; I have a few more things to work through, but I think I can figure it out from here...!