Only Add Negative Numbers

New Here ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Hello ladies and gentlefolks!

 

I have a form in which a section of it utilizes numbers - both negative and positive numbers. The options are set to change negative numbers to be red and in parenthesis. I also created an additional field - but what I need for it to do is to only take the numbers that are of a negative value and add only those negative values together (ignoring thje positive or zeros) to give me a grand (negative) total. I use Acrobat Pro DC (not sure if this all of the information that is needed).

 

Thank you so much in advance.

TOPICS
Edit and convert PDFs, How to, JavaScript, PDF forms

Views

88

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 1 Correct Answer

Most Valuable Participant , Apr 12, 2021 Apr 12, 2021
You can use this code as the custom calculation script of the field that should display the total owed amount: var total = 0; for (var i=1; i<=16; i++) { var v = Number(this.getField("R"+i+"B").valueAsString); if (v<0) total+=v; } event.value = total;

Likes

Translate

Translate
New Here ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

I guess I could have attached a screenshot....  Here is more of what I am trying to do...

 

All of the fields labeled as "RxB" will have the numbers in the (either a positive or a negative)

The "Total Owed" field should only be calculating all of the negative numbers from the "RxB" fields.

 

I hope this clarifies and that my attachment uploaded correct (new MacBook)

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
Most Valuable Participant ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

You can use this code as the custom calculation script of the field that should display the total owed amount:

 

var total = 0;
for (var i=1; i<=16; i++) {
	var v = Number(this.getField("R"+i+"B").valueAsString);
	if (v<0) total+=v;
}
event.value = total;

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
New Here ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

LATEST

That works flawlessly! Thank you! You're a genious - I have used many of your suggestions as I am learning all of this!

 

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