4 Replies Latest reply on Apr 17, 2009 12:21 PM by NMannon

    Help with a JavaScript Warning

      I have created a form that added fields into total fields.  The total fields are then added together.  In another part of the form there is addition and subtraction that gives another total.   If these two totals do not equal then a number is plugged into one of two fields Over or Short according to which be the case.  My problem is that all of these fields are set for the number format with 2 decimal places but as soon as you enter the last number the warning

      "The value entered does not match the format of the field [Over] and if you click enter another message with the same wording just for Short comes up.  This happens when there is no offage.  It does not happen if there is a number to plug in the short or over fields.


      At this time it does not recalculate and the numbers that should have changed to 0 stays in place.  This causes the ending total to be off.


      There is a custom validation to not show negative numbers.  The validation that is keyed is as follows:

      // null field if number is negative

      if (event.value<0) event.value="";

      This script is keyed into the over and short fields.

        • 1. Re: Help with a JavaScript Warning
          gkaiseril MVP & Adobe Community Professional

          Have you tried setting the format of the over/short filed to "None" to see what is being placed into the field?


          You could also print the value to the console or pop an alert with the computed value.


          My guess is the value will be "NaN", Not a Number, because there is a null or blank field in one of the fields you are usng in a prior calculation.

          • 2. Re: Help with a JavaScript Warning
            Level 1

            The fields Over and Short could show a negative value.  But negative values need to show as 0 and calculate as 0.  Only one of these fields can have a value other than 0(this is a either or situtation).  I have tried showing the format as none with the same result.

            • 3. Re: Help with a JavaScript Warning
              gkaiseril MVP & Adobe Community Professional

              What are the values your are getting for all the involved fields?


              Are the results of your calculations correct?


              Exactly what field is throwing the error?


              Change all the fields that are calculated to a format of "None" so you can see what values are being placed in the field. You should then verify that those values are correct. Or you can add some debugging scripts into you calculation scripts to report the results to the JavaScript console and check that the values computed are correct.


              JavaScript is not strict about data typing so if the interpreter thinks it is dealing with number the values will be added, but if it comes on a value and thinks that value is a string then it will start concatenating the values.


              For example:
              1 + 2 + 3 + 4= 10


              or with 3 as a string:
              1 + 2 + "3" + 4 = 334

              • 4. Re: Help with a JavaScript Warning
                Level 1

                The fields involve are totals of currency.  There are 4 columns that are added together to come up with a TotalCash sum.  In another area I have a field named OldBalance that together with a field named CashIn(+) and CashOut(-) gives the sum of NewBalance.  The sum of NewBalance should equal the Sum of TotalCash if not then either the Over or the Short field should have a sum plugged, therefore; Over or Short can not show a negative number or sum a negative number.


                The calculations for the NewBalance is correct.  The calculation for TotalCash is correct.  The problem is that when you plug the number into CashOut the error messages comes up.  If you answer ok to the 2 error messages and then delete the numbers in the over or short field the Total field is correct.  If not the number that should have cleared when entering the CashOut field stays and caused the Total field to be out of balance.  I should add that if the sheet is out of balance that it will not let you clear the field.


                I tried changing the format to none and the same errors popped up.