4 Replies Latest reply on Jun 16, 2016 12:06 PM by steven85265304

    If Then Statement

    steven85265304

      Hello,

       

      I am using Adobe Acrobat XI Pro.  I have created a text field (textfield1) where the value equals textfield 2 + textfield 3).  I would like users to be able to add their own data if the values of text field 2 & 3 do not apply.

       

      Example:

       

      // Get the field values, as strings
      var s1 = getField("ReceiptLine1").valueAsString;
      var s2 = getField("Name").valueAsString;

       

      // Combine values, separated by a space

      event.value = s1 + " " + s2;

       

      else

       

      Value = User can add their own data

      ______________

       

      I hope this makes sense.  Any help would be appreciated.

       

      Thank you.

        • 1. Re: If Then Statement
          George_Johnson MVP & Adobe Community Professional

          What do you mean by "if the values of text field 2 and 3 do not apply", exactly? Do you mean if either or both are blank, or something else?

          • 2. Re: If Then Statement
            steven85265304 Level 1

            Sorry, I meant that it could be something else if needed.

            • 3. Re: If Then Statement
              George_Johnson MVP & Adobe Community Professional

              One thing you can do is revise the script to the following:

               

              // Custom calculation script

              (function () {

               

                  // Get references to the input fields

                  var f1 = getField("ReceiptLine1");

                  var f2 = getField("Name");

               

                  // Set this field value if either input field changes

                  if (event.source === f1 || event.source === f2) {

                      event.value = f1.valueAsString + " " + f2.valueAsString;

                  }

               

              })();

               

               

              The user will then be able to enter a custom entry, but it will get overwritten if either of the input field values are changed. The other way to do this is with scripts in the validate events of the input fields. They would get the value of the other input field, create the string, and set the value of the third field to the string. Somehting like:

               

              // Custom Validate script for ReceiptLine1 field

              (function () {

               

                  // Get the other field value

                  var s1 = getField("Name").valueAsString;

               

                  // Set the other field value

                  getField("textfield1").value = event.value + " " + s1;

               

              })();

               

              The validate script for the Name field would be similar.

              • 4. Re: If Then Statement
                steven85265304 Level 1

                Awesome!! It worked perfectly.  Thank you very much

                 

                Steve