6 Replies Latest reply on Mar 7, 2014 4:10 AM by Test Screen Name

    Javascript to suppress 0.00 when printing form

    fsliving

      I have an issue that is very similar to the one described here (http://forums.adobe.com/message/3205780#3205780). Over the last 4 days, I've tried, to no avail, to get the desired results. I am very desperate for some help. Here's my case: I’m running Adobe Pro 9 on XP OS. I created an interactive order form which has 10 rows, the first of which is "required" and the other 9 rows are "optional". Each row consists of the following fields: qty_ordered(i), unit_price(i) and amt(i), where i ranges from 1 to 10. qty_ordered(i) is defined as an integer and unit_price(i) and  amt(i) are defined as numeric with 2 dps (with no currency symbol). The amt(i) field is calculated as the product of qty_ordered(i) and unit_price(i).

       

      Need javascript help.gif

       

      A new field, subtotal is defined as numeric with 2 dps and "$" currency symbol. This subtotal field is calculated as the sum of amt(1) + amt(2) + amt(3) + ….. + amt(10). There will be occasions when fewer than 10 rows are completed. WHEN THE FORM IS BEING PRINTED, is there a way to suppress the 0.00s (that is, replace them with "blank"? I setup a javascript for the "Print Form" field, as follows:

      // This script will print the completed order form

      // If the amt field is 0.00, then clear the field (print blank)

       

      if (amt2=0.00) {  amt2="";  }

      if (amt3=0.00) {  amt3="";  }

      if (amt4=0.00) {  amt4="";  }

      if (amt5=0.00) {  amt5="";  }

      if (amt6=0.00) {  amt6="";  }

      if (amt7=0.00) {  amt7="";  }

      if (amt8=0.00) {  amt8="";  }

      if (amt9=0.00) {  amt9="";  }

      if (amt10=0.00) {  amt10="";  }

       

      // Set the print parameters

      var pp = this.getPrintParams();

       

      // Print the form and close it

      pp.interactive = pp.constants.interactionLevel.silent;

      pp.printContent = pp.constants.printContents;

      this.print(pp);

       

      // Close the form

      this.closeDoc(true);

       

      // Exit Adobe Acrobat

      Exit();

        • 1. Re: Javascript to suppress 0.00 when printing form
          gkaiseril MVP & Adobe Community Professional

          Have you opened the JavaScript console to see if there are any other errors with your script?

           

          Have you tried to set the fields to a format of "Number' with 2 decimal places and no currency symbol?

           

          I have found that if you use the currency symbol in the format one cannot suppress the "$0.00", it  can only be suppressed with the "Number" format and no currency symbol.

           

          If that is your entire script, how are you accessing the field objects for the amount fields?

           

          You need to first access the field object before testing the "value" property of the field or setting the "value" property of the field.

          • 2. Re: Javascript to suppress 0.00 when printing form
            fsliving Level 1

            Thank you, GKaiseril,

             

            I should have mentioned in my previous post that I am not a programmer. Please pardon my ignorance when I say that I am uncertain what you mean by, "Have you opened the JavaScript console to see if there are any other errors with your script?" If by this you mean, if I received any syntax errors when I saved the JavaScript for my "Print Form" button, then the answer is, "No. I did not get any syntax error."

             

            Next, I did not use the currency symbol for either unit_price(i) or amt_(i).

             

            Yes, this is my entire script. Should I have VAR statements for amt(i)? I have to admit that I really have no clue what I am doing. I only know about VAR statements only because I’ve been looking at a lot of code over the last few days.

             

            So then, are you suggesting that, before the statements that I already have, I should put the following VAR statements?

            var amt(2) = 0.00;

            var amt(3) = 0.00;

            var amt(4) = 0.00;

            .

            .

            .

            var amt(10) = 0.00;

             

            GKaiseril, I am really hoping that you can help me with the code because I really can’t spend longer than today on this task. My job is on the line. To further clarify, here is what I wish to accomplish.

             

            Doc1.gif

             

            NOTE: If there is a more efficient solution to suppressing the 0.00s, other than through a JavaScript under the "Print Form" button, I'd be happy to try it (as long as it is not too complex for me to understand and implement).

             

            Thank you so much, in advance, for your kind assistance, GKaiseril.

             

            Sincerely,

             

            Fsliving

            • 3. Re: Javascript to suppress 0.00 when printing form
              Test Screen Name Most Valuable Participant

              Sorry, but you are a programmer now. When you write JavaScript, that's what you are doing, and there are many new and interesting things to learn beyond copy/paste. When there is an error in your JavaScript you do not get a large pop-up. Rather, messages appear in the JavaScript console. You must open that console and check it for errors as you create your program - even the most experienced make constant mistakes that need to be caught. The messages are often obscure, and we can often help.

               

              The point about your code which begins using amt2 is that amt means nothing at all and isn't connected to the field called amt2 unless you connect it. You do this usually using getField, which you should find in many examples as well as the documentation.

              • 4. Re: Javascript to suppress 0.00 when printing form
                gkaiseril MVP & Adobe Community Professional


                I would use the custom validation field for each "amnt#" field to supresss the zero value as well as the other fields. The validation script can be as simple as;

                 

                if(event.value == 0) event.value = ""; // suppress a zero value;

                 

                This script works no mater how the calculation for the field is performed. The form will have to recalculate for the validation scripts to run. You can enter a value into a field or clear the form to accompllis the recalculation.

                 

                You will still have other issues with your script.

                • 5. Re: Javascript to suppress 0.00 when printing form
                  fsliving Level 1

                  I want to thank you, GKaiseril and Test Screen Name, for your help. Sadly, I've had to abort the exercise. Time did not permit me to continue working on it. I had to accept defeat. Fortunately, my job was not threatened by this.

                   

                  I tried both of your recommendations. I have no doubt that they would have worked, or taken me closer to the solution, had I pursued them. However, my lack of familiarity with JavaScripting hampered me and I had to be realistic that I could not learn it in the very short time that I had to come up with the solution ... Not everyone has the aptitude to be a programmer. What comes natural to you, is very intimidating to me. Anyway, I'm not a quitter. One of these days, time permitting, I will attempt to accomplish the desired results. Thank you both, again! All the best! 

                  • 6. Re: Javascript to suppress 0.00 when printing form
                    Test Screen Name Most Valuable Participant

                    You may well have the aptitude... and it all looks intimidating at first. But what you do need (and realistically identify) is time, and lots of it, to learn by practicing, and a willingness to read lots and lots of stuff. Good luck!