"The value entered does not match the format of the field" and zeroes instead of no value

Community Beginner ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

I am calculating the value of ((a+b)/a) and placing the result as a percentage in a third field.

 

Here is the formula:

 

var a =this.getField("APG3");
var b =this.getField("Cost");
if(b.value != 0) {
event.value=((a.value+b.value)/a.value);
} else {
event.value = "";
}

 

Fields "APG3" and "Cost" are formatted as numbers. The result field is formatted as a percentage.

I get incessant "The value entered does not match the format of the field [ CH1 ]" and "The value entered does not match the format of the field [ CH2 ]" error messages when I enter values into "APG3" and "Cost."

 

How do I banish the error messages?

 

Also, the result field displays "0%" instead of a blank field when no values are present in the other two fields. How do I display nothing instead?

TOPICS
PDF forms

Views

102

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
community guidelines

correct answers 2 Correct Answers

Adobe Community Professional , Feb 20, 2021 Feb 20, 2021
Try this as custom format script:event.value = event.value + "%"; if(event.value == "%" || event.value == "Infinity%") event.value = "";

Likes

Translate

Translate
Engaged , Feb 20, 2021 Feb 20, 2021
Just add *100 in your calculation code.

Likes

Translate

Translate
Adobe Community Professional ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Are you inputing number first in "Cost" field?

Empty field is considered as 0 so if you input value in "Cost" field while "APG3" field is empty, script would try to divide with 0 and you can't do that, thats why probably you get alert.

Also to show blank  instead of  0% you would need custom format script.

 

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
community guidelines
Community Beginner ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

I've cured the divide by zero errors.

 

How do you format the result field so it displays nothing when the calculation fields are empty?

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
community guidelines
Adobe Community Professional ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

That's not possible with a Percentage field. If you want to suppress the zero value you have to set the field as having a custom Format script, and then you can add the "%" character yourself to it.

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
community guidelines
Community Beginner ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Could you give me a few clues as to how to achieve this, please? Thank you!

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
community guidelines
Adobe Community Professional ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Try this as custom format script:

event.value = event.value + "%";
if(event.value == "%" || event.value == "Infinity%") 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
community guidelines
Community Beginner ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Thank you. That almost does it. Only problem is that the value needs to be *100 to get the proper percent. (IOW, I get 1.5% when I should get 150%)

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
community guidelines
Engaged ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Just add *100 in your calculation code.

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
community guidelines
Community Beginner ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

LATEST

Yesss! Thank you, @Nesa Nurani and @Asim123 for the great help. All sorted!

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
community guidelines