9 Replies Latest reply on Jun 11, 2008 2:14 PM by Bill Lomax

    Field value equals zero then Invisible

    Bill Lomax Level 1
      Hello, I'm very new to JavaScript. I have a form where there are a number of fields that perform simple math, e.g., SUM = A - B. What I want the end form to do is not show a total of 0.000 when the fields A and B have no input. How do I accomplish this? Also, when I "enable User Rights In Adobe Reader" is that going to impact the Script?
        • 1. Re: Field value equals zero then Invisible
          gkaiseril MVP & Adobe Community Professional
          Test to see if field A or B has any inputted value before performing the calculaiton.

          In AcroForms JavaScript custom calculation scirpt:

          (if(this.getField("A").valueAsString != "" | this.getField("A").valueAsString != "')
          event.value = this.getField("A").value - this.getField("B").value;

          LiveCycle Designer calcuation in FormCalc

          if(HasValue(A) or HasValue(B) then
          A - B
          else
          ""
          endif
          • 2. Re: Field value equals zero then Invisible
            Bill Lomax Level 1
            Thank you Geo, I've added the LiveCycle Designer calculation, and the cumulative field is blank when A or B has no value; however, it is still blank when I add values into the A or B fields.

            I am typing these straight into "Text Field Properties", the script works as above in the "simplified field notation" but returns an error of "missing ) after condition 1: at line 2" when entered in the "Custom calculation script" JavaScript Editor.

            if(HasValue(Baseline1) or HasValue(InstalledOnPeak1) then
            Baseline1-InstalledOnPeak1
            else
            ""
            endif

            What am I missing here?
            • 3. Re: Field value equals zero then Invisible
              Bernd Alheit Adobe Community Professional & MVP
              > What am I missing here?

              For every ( you must enter a ).
              • 4. Re: Field value equals zero then Invisible
                Bill Lomax Level 1
                Thank you Bernd, (and Geo)

                It has been way too long since I took a FORTRAN class (Yes, I know this is JavaScript), and whatever programming skills I had then have been forgotten. Yes, _now_ I see that I need to balance the parenthesis, so simple when you are familiar with the language. Looks like a book is in order here to bone up on my skills, any suggestions?
                • 5. Re: Field value equals zero then Invisible
                  Bernd Alheit Adobe Community Professional & MVP
                  You must look for the balance of parenthesis in every programming language.
                  • 6. Re: Field value equals zero then Invisible
                    Bill Lomax Level 1
                    I gather that it's a must to tell people whom your asking help from HOW you're encoding your JavaScript. I'm on a Macintosh, and using Acrobat 8 to add interactive functionality to a PDF that was originally generated in QuarkXPress (not my first choice).

                    I have followed the suggestions, and been inputting the coding into the dialog boxes located here: Text Field Properties > Calculate > Custom Calculation Script. The Syntax for EMPTY () must be different. I keep getting error feedback from the CCS dialog when I hit OK.

                    I did more research in the Forum and found another suggestion from Geo Kaiser that appears to resolve my problem. I went back to my Simplified Field Notation of A-B, and then used the Geos Validation Script.

                    In the field's property window select the "Validation" tab press the "Edit" button next to the "Custom validation script" and enter: 

if (event.value ==0) event.value ='';

                    End result, all the fields are blank after I clear my test data with Clear Form, and it can then be saved as a pristine document.

                    Thanks to all that participate here, its not easy to find an answers for even simple questions like mine.
                    • 7. Re: Field value equals zero then Invisible
                      Bill Lomax Level 1
                      I gather that it's a must to tell people whom your asking for help HOW you're encoding your JavaScript. I'm on a Macintosh, and using Acrobat 8 to add interactive functionality to a PDF form that was originally generated in QuarkXPress (not my first choice).

                      I have followed the suggestions, and have been inputting the coding into the dialog boxes located here: Text Field Properties > Calculate > Custom Calculation Script. The Syntax for EMPTY () must be different. I keep getting error feedback from the CCS dialog when I hit OK.

                      I did more research in the Forum and found another suggestion from Geo Kaiser that appears to resolve my problem. I went back to my Simplified Field Notation of A-B, and then used the the following Validation Script.

                      In the field's property window select the "Validation" tab press the "Edit" button next to the "Custom validation script" and enter: 

if (event.value ==0) event.value ='';

                      End result, all the fields are blank after I clear my test data with Clear Form, and it can then be saved as a pristine document.

                      Thanks to all that participate here, its not easy to find an answers for even simple questions like mine.
                      • 8. Re: Field value equals zero then Invisible
                        gkaiseril MVP & Adobe Community Professional
                        The problem is there are 2 PDF form creation products available through Adobe Acrobat. There is the AcroForms available to both Windows and MacIntosh computers that use Acrobat JavaScript. And there is LiveCycle Desinger available only to Windows. LiveCycle Designer supports scripts in FormCalc and JavaScript, with some modification from ArcoForms.

                        So posters have to be very clear as to what product and language they are using.

                        And there are always many ways to program a solution, but if I am already doing a custom calculation script, I just finish my formatting there. And I prefer not to use the "short cut" options because they tend to limit naming functionality and the use of functions that add so much more processing flexibility. Like applying the same calculation to an array of fields or having repeated code in one and only one location.
                        • 9. Re: Field value equals zero then Invisible
                          Bill Lomax Level 1
                          Hello Geo, I agree with you. I'm doing patchy coding, and its bad practice. Unfortunately, it's a case of working through it myself. I am retaining what I learn as I proceed.

                          I haven't yet finished this project; it's out for review. In looking for more information, I came upon an article by Ted Padova that states: "Form fields add a lot of overhead to your PDFs and when you need to host files on the web or exchange files via email, you want to trim the file sizes as much as possible."

                          File size is something to which I wasn't paying close attention. Since the end form will be distributed via the Internet, a smaller file size would be advantageous. The page Im working on has almost 100 fields; and 25 of those fields perform simple calculations. I assume that a more adept coder would use array commands that could cut down the size of the end file significantly.

                          Is there a printed how-to reference that is geared for novices that specifically deals with forms?