5 Replies Latest reply on Aug 11, 2011 12:40 AM by maxwyss

    Have text be visible or hidden depending on a form value

    cwhicks

      We have an automated system that sends out a ticket for a performance as a PDF. There are forms on the PDF that are filled out with the seat information, like Loge, Row 8, Seat 12. I would like the PDF to show a line of text when the Section form says "Loge", and not show the text when it says anything else. I have tried multiple javascripts I found on the Googles in the Validate and Calculate fields and none work. In fact, I never get any text to show up no matter what I do. I am thinking those scripts are for when someone is filling out a PDF and it does the validation then. This is not a form the is filled out by the end user, just emailed out as a static document.

       

      Is this possible?

       

      Thanks

        • 1. Re: Have text be visible or hidden depending on a form value
          George_Johnson MVP & Adobe Community Professional

          So how exactly are the form fields getting populated with data?

          • 2. Re: Have text be visible or hidden depending on a form value
            cwhicks Level 1

            It is done programatically. We have the PDF with all the blank forms sitting in a directory, when a ticket is purchased, a little app runs a SQL statement, pulls the data and puts it into the approriate fields and emails it out. I don't have the ability to modify that app, so I wanted to do something within the PDF itself.

            • 3. Re: Have text be visible or hidden depending on a form value
              gkaiseril MVP & Adobe Community Professional

              Please realize that JavaScirpt has many variations. There is a subset that is web based, there is a set that run on your local computer, and there is the Acrobat JS extension. Google finds these types of scripts and other items like the Java language, a whole different computer language from JavaScirpt.

               

              Many of the responders here can adjust the web scripts to work in Acrobat.

               

              Are you getting any errors in the JavaScirpt console in Acrobat?

               

              Without knowing how your custom application builds the PDF and if you can update the web located PDF will determine if you can modify it.

               

              You will have to provide a lot more information to get help. JavaScript is an object scripting language, so object names are needed and the logical contents of the field.

               

              You could try:

               

              // custom calculation for additional field text;
              // get the section name field;
              // change the quoted string value to the name of the necessary field name;

              var cSectionName = "SectionFieldName";
              // get the value of the section name field;
              var cSectionValue = this.getField(cSectionName).value;
              // convert section name value to an array;
              var aSectionValue = cSectionValue.split(" ");
              // test for the section name of Loge - the 0 element of the zero based array for the section field name value;
              if(aSectionValue[0] == "Loge") {
              // display this field;
              this.getField(event.target.name).display = display.visible;
              } else {
              // not Loge so hide the field;
              this.getField(event.target.name).display = display.hidden;
              }

               

               

              You will need to change the string   "SectionFieldName" to the string name of the field in which the section data is located.

              • 4. Re: Have text be visible or hidden depending on a form value
                George_Johnson MVP & Adobe Community Professional

                Is the word "Loge" in a text form field, or is the PDF flattened on the server before it is served to the user? If it's in a form field, you can set up the PDF to run a script when it opens that checks the field to see if it includes "Loge" and populates another field with the text you want to display. This code could either be placed as a document-level script (outside of a function definition) or in a page's Page Open event. If the form is flattened, you can still search a page for the word "Loge" and populate a field with the text you want to display, again with a script that executes when the document is opened. If you need more help, post again with more information about how the document is set up.

                • 5. Re: Have text be visible or hidden depending on a form value
                  maxwyss Level 4

                  The nature of the documents you want to send out (document representing a value) makes it preferrable to completely prepare them on the server side. Which means that you would do better to add a variable text server-sided. This also means that you can control your text directly in the script accessing the database (and moves the logic there). Getting that information onto your document can be done with a stamping or form filling utility.

                   

                  Hope this can help.

                   

                  Max Wyss.