3 Replies Latest reply on Jun 17, 2012 2:21 PM by gkaiseril

    Document level script to display zeros in calcuated field

    BeardedLady

      I have created a form, with the calculated fields set to read only, and with a validation script of

       

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

       

      (so that the calculated fields do not display as $0.00)

       

      All but four of the calculated fields are named Item.0, Item.1 etc., plus there are SubTotal, ShippingCharge, CCFee and Total fields that need to stay blank until data is entered into the form.

       

      Initially, I tried to add the script as a document level script, but it didn't work and I'm thinking it needs more to the script to use at the document level, but I have no idea what more it needs.

       

       

       

      Where did I go wrong?  It certainly would be quicker to add calculated fields if I didn't have to add that validation script to each.

        • 1. Re: Document level script to display zeros in calcuated field
          enomail Level 1

          Hi BeardedLady

           

          Do you want the document level script to "display" or "hide" the zeros.

          I'm thinking the zeros are displayed by default.

          Why would you put a validation script to hide the zeros and then a document level script to display them?

           

          Ron A

          • 2. Re: Document level script to display zeros in calcuated field
            BeardedLady Level 1

            I guess my question wasn't clear.  I want a document level script to hide the zeros, rather than having to add the script to each and every calculated field.

            • 3. Re: Document level script to display zeros in calcuated field
              gkaiseril MVP & Adobe Community Professional

              Even with a document level script you would need to call it in every calculated field.

               

              I you were to write "app.alert("Hello World");" as a document level function, it would only execute when the PDF was initialized or opened and not again as long as the PDF remained open.

               

              If you rote a document level function using JavaScript like:

               

              function Hello() {

              appp.alert"Hello World, I am a function");

              return true;

              }

               

              It would never run until called  with  a JavaScript statement like "Hello();"

               

              So even with a document level script and preferably a function, you still would need to edit every calculation to call the function or the script would never run.

               

              You could also create a document level function to suppress the zero display and then write more code to add the call to this function to the calculated fields.

               

              You need to learn more about the scope of items, how events are processed within a PDF, what functions are and how to use them effectively. You might want to start with getting or linking to a copy the Acrobat JS API Reference.