5 Replies Latest reply on Oct 18, 2013 9:24 AM by LeonaB17

    Value Entered does not match format of field

    LeonaB17

      Hi,

       

      I need assistance with an error message I'm receiving. I have received this message before and received some excellent advice on how to fix it, but I am unable to apply that same solution to this situation as it is different.

       

      I have a form with 5 fields. The math for these fields should go as follows:

       

      Field 1 (JF01)  -  Field 2 (JF01a) = Field 3 (JF01b) + Field 4 (JF01c) = Field 5 (JF01d)

       

      Here are the scripts I have on the calculate tabs of the two "total" fields:

      (I have all fields formatted to Number with 2 decimal places and a dollar sign with no space)

       

      JF01b:

      var myField = this.getField("JF01b"); myField.value = Number(this.getField("JF01").value) - Number(this.getField("JF01a").value);

       

      JF01d:

      var myField = this.getField("JF01d"); myField.value = Number(this.getField("JF01b").value) + Number(this.getField("JF01c").value);

       

      Everything works beautifully - UNTIL - JF01d = zero. If that last field happens to add up to zero that's when I get the error message and I have no idea why. If that field adds up to a number above zero, or even a negative number, it is just fine. But it just won't have a zero.

       

      Any advice is GREATLY appreciated!!

       

      Thanks!!

       

      ***EDIT

      I just noticed some numbers which equal zero work fine, but for some reason others don't.

      For instance:

      $10.00 - $50.00 = -$40.00 + $40.00 = $0.00   works fine no problem, but

      $180.00 - $190.80 = -$10.80 + $10.80 = -$10.80  last field should be zero - not -$10.80, and error message pops up

       

      So it appears the error only happens when there are numbers other than zeros after the decimal. (Which confuses me further.)

        • 1. Re: Value Entered does not match format of field
          gkaiseril MVP & Adobe Community Professional

          Verbal explanations are not always clear and a subject to the poster's preconceived ideas. It would be helpful to post a link to a sample of the form.

           

          Things to look at are the field calculation order, making sure all the values you are trying to add are numeric strings and not character strings of numbers. The "+" is the additive and concatenation operator. JavaScript makes the assumption that if any variable looks like a string, concatenation will be done.

           

          Numbers with decimals are stored as IEEE floating point values and most decimal values become irrational values so you may need to perform some rounding of intermediate values.

           

          Where a script is placed may affect how to set the value of the focused field. If you are trying to set the value of a given field from within the field, you need to use the "event.value" to modify the field's value.

          • 2. Re: Value Entered does not match format of field
            George_Johnson MVP & Adobe Community Professional

            The likely cause is the result of the subtraction is a number very close to zero, but not quite, that is represented in scientific notation (e.g., -1.23456e-15), which confuses the formatting routines that Acrobat uses. You can prevent it by rounding the result of the calculation, for example:

             

            // Subtract and round to two decimal places

            event.value = util.printf("%.2f", +getField("JF01").value - +getField("JF01a").value);

            • 3. Re: Value Entered does not match format of field
              LeonaB17 Level 1

              George, Thanks so much for responding. Can you tell me exactly where I would add that script and how it would look? (My skill level with javascript is very minimal.)

               

              Would it go on the calculate tab of JF01b (the field that subtracts) and would it look like this?

               

              var myField = this.getField("JF01b"); myField.value = Number(this.getField("JF01").value) - Number(this.getField("JF01a").value);

              // Subtract and round to two decimal places

              event.value = util.printf("%.2f", +getField("JF01").value - +getField("JF01a").value);

               

              Or does the script you provided need to be placed somewhere else or integrated into my script somehow?

               

              Thanks again!

              • 4. Re: Value Entered does not match format of field
                George_Johnson MVP & Adobe Community Professional

                It would replace the custom calculation script that you have for the JF01b field.

                • 5. Re: Value Entered does not match format of field
                  LeonaB17 Level 1

                  Oh that totally fixed it!! Thank you so much George!! You're the best!