Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

When entering data into text field I get this message - “The value entered does not match the format of the field [CostPerAnnualSales]”(

New Here ,
Jul 20, 2018 Jul 20, 2018

I have a very simple PDF form for our reps to fill out, it consists of text fields and a few fields with numbers. Two of the number fields are calculated in a separate number field with this custom calculation for a percentage outcome:

event.value = (this.getField("TotalDispenserCost").value/ this.getField("ExpectedAnnualSales").value)

It calculates correctly, but when I enter text into the text fields or I trigger the Clear Form, Print Form or Email Form buttons before I enter data into the “TotalDispenserCost” and the “ExpectedAnnualSales” fields I get the following message “The value entered does not match the format of the field [CostPerAnnualSales]”(this is the field that calculates the percentage). BUT I noticed if I enter the numbers into the “TotalDispenserCost” and the “ExpectedAnnualSales” fields first and then enter data in the text fields the message does not appear.

I can’t seem to find this same type of problem on any of the forums that I’ve visited for help. Hope there is a very simple solution to this issue.

TOPICS
PDF forms
14.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
LEGEND ,
Jul 20, 2018 Jul 20, 2018

You're doing a division, and when you do that when the ExpectedAnnualSales field is blank (or zero), you're dividing by zero, which will result in something that can't be displayed in a field that's set up with a numeric format. The fix is to check to see if the denominator evaluates to zero, and if so, set the calculated value to something like blank. For example:

var numerator = +getField("TotalDispenserCost").value;

var denominator = +getField("ExpectedAnnualSales").value;

if (denominator !== 0) {

     event.value = numerator / denominator;

} else {

    event.value = "";

}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 20, 2018 Jul 20, 2018

You're doing a division, and when you do that when the ExpectedAnnualSales field is blank (or zero), you're dividing by zero, which will result in something that can't be displayed in a field that's set up with a numeric format. The fix is to check to see if the denominator evaluates to zero, and if so, set the calculated value to something like blank. For example:

var numerator = +getField("TotalDispenserCost").value;

var denominator = +getField("ExpectedAnnualSales").value;

if (denominator !== 0) {

     event.value = numerator / denominator;

} else {

    event.value = "";

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 29, 2020 Sep 29, 2020

George,

Using the same example, what would the Acrobat JavaScript coding be for the same issue (same error message) when multiplying instead of dividing?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2020 Sep 29, 2020

Multiplying should not produce this error, unless you're multiplying non-numbers. If you are getting this result it means the value of one of the field could not be converted to a number, which will result in NaN.

To overcome that you can do something like this:

 

var a = Number(this.getField("A").valueAsString);

var b = Number(this.getField("B").valueAsString);

if (isNaN(a) || isNaN(b)) event.value = "";

else event.value = a * b;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 30, 2020 Sep 30, 2020

Thank you @try67!

I'm working on a tool in Adobe that calculates growth: percentages, dollar amounts, and averages. I ran into this issue with dividing and applied George's solution, which fixed the issue. Today I'm going to try multiplying, so I was hoping to get ahead of any potential issues (of which I'm glad to hear there shouldn't be since I'm using numbers). I may be back today to pick your brain!

 

Thanks-a-million!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 05, 2020 Oct 05, 2020

@try67 or @George_Johnson,

What coding would I use if I want to use two math functions (such as, addition and division together)? For example: (Field 1 + Field 2) / Field 3

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2020 Oct 05, 2020

You can use this code:

 

var v1 = Number(this.getField("Field 1").valueAsString);
var v2 = Number(this.getField("Field 2").valueAsString);
var v3 = Number(this.getField("Field 3").valueAsString);
if (v3==0) event.value = "";
else event.value = (v1+v2)/v3;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 05, 2020 Oct 05, 2020

Thank you, @try67! Much appreciated. If I wanted to use Field 1 or Field 2 / Field 3 or Field 4, would I follow a similar coding? Last question, I swear!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2020 Oct 05, 2020

Yes...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 06, 2020 Oct 06, 2020

Thanks-a-million, @try67 ! Everything worked perfectly in my calculations when I conducted the beta testing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2018 Jul 20, 2018

George, I knew it was a simple answer, but because of my lack of Acrobat JavaScript I was having a difficult time solving the issue.

Thank You so much!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 08, 2021 Jan 08, 2021

Hi,

I have the same problem. The formula is Expense1/Expense2*Expense3. Teh calculation is correct, but when I try to enter other values i get the same error. The below is the message that shows in the JavaScript Editor. I am really new to Adobe and need to ahve the form ready by 1-12-21. Any help is much appreciated. Thank you,

 

 

//-------------------------------------------------------------

//-----------------Do not edit the XML tags--------------------

//-------------------------------------------------------------

 

//<AcroForm>

//<ACRO_source>Result:Calculate</ACRO_source>

//<ACRO_script>

/*********** belongs to: AcroForm:Result:Calculate ***********/

/** BVCALC Expense1/Expense2*Expense3 EVCALC **/event.value=AFMakeNumber(getField("Expense1").value)/AFMakeNumber(getField("Expense2").value)*AFMakeNumber(getField("Expense3").value)

//</ACRO_script>

//</AcroForm>

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2021 Jan 08, 2021

Read the replies above. This happens when you divide by zero.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 08, 2021 Jan 08, 2021

The calculation is NOT correct because it produces an error. The error happens for the reasons noted and explained already.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2021 Jan 11, 2021

Thank you for help,

I managed to do correct that, but I have another issue.

var v1 = Number(this.getField("Expense1").valueAsString);
var v2 = Number(this.getField("Expense2").valueAsString);
var v3 = Number(this.getField("Expense3").valueAsString);
if (v2==0) event.value = "";
else event.value = v1/v2*v3;

It calculates correct, but the box where the result appears does not show 0.00, the format is number and 2 decimals which has worked for all other box results. Once I imput Expense1 and Expense2, the 0.00 appears in the result box and it changes later to the correct result when I imput Expense3. Could you please help?

Thank you,

 
 
 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2021 Jan 11, 2021

The divider in your formula is not v2, but v2*v3. That's what you need to check is zero, or both v2 and v3.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2021 Jan 11, 2021

how do you that? even if I imput (Expense1/Expense2)*Expense3, it still does not show 0.00

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2021 Jan 11, 2021

Is the formula (v1*v2)/v3 or v1/(v2*v3)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2021 Jan 11, 2021

It is (V1/V2)*V3

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2021 Jan 11, 2021

The calculation is correct. No problems with that.

 

The issue is that the formatting of the total box before imputing any amount in V1/V2*V3 does not show 0.00. It shows 0.00 when I input V1 and V2 and once I input V3, it show the correct calculation.

I would like the total box to show 0.00 before inputing any amount in the value boxes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2021 Jan 11, 2021

That is not a correct result, but if you really want to do it change this line:

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

To:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2021 Jan 11, 2021

It looks correct since it is Personal miles/Total miles and that result multiply by the lease amount value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2021 Jan 11, 2021

I made the change and it shows 0.00. Will come back for help if it turns out it is not correct.

Thank you for your help. Million thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2021 Jan 11, 2021
LATEST

It's not correct because X/0 does not equal zero.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2021 Jan 11, 2021

When you don't enter a value in Expense3 the value of v3 is 0.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines