Highlighted

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

Copy link to clipboard

Copied

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.

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

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 = "";

}

TOPICS
Macintosh, PDF forms

Views

1.9K

Likes

Translate

Translate

Report

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

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

Copy link to clipboard

Copied

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.

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

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 = "";

}

TOPICS
Macintosh, PDF forms

Views

1.9K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 20, 2018 0
Adobe Community Professional ,
Jul 20, 2018

Copy link to clipboard

Copied

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 = "";

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 20, 2018 3
Community Beginner ,
Sep 29, 2020

Copy link to clipboard

Copied

George,

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 29, 2020 0
Most Valuable Participant ,
Sep 29, 2020

Copy link to clipboard

Copied

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;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 29, 2020 1
Community Beginner ,
Sep 30, 2020

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 30, 2020 0
Community Beginner ,
Oct 05, 2020

Copy link to clipboard

Copied

@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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 05, 2020 0
Most Valuable Participant ,
Oct 05, 2020

Copy link to clipboard

Copied

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;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 05, 2020 1
Community Beginner ,
Oct 05, 2020

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 05, 2020 0
Most Valuable Participant ,
Oct 05, 2020

Copy link to clipboard

Copied

Yes...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 05, 2020 1
Community Beginner ,
Oct 06, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 06, 2020 0
New Here ,
Jul 20, 2018

Copy link to clipboard

Copied

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!!!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 20, 2018 0