Skip to main content
Matteo95
Participant
November 1, 2018
Answered

Check box to increment/decrement a text field in Acrobat

  • November 1, 2018
  • 1 reply
  • 1754 views

I have a list of items that need to be added to a variable if the corresponding checkbox next to each line item is checked, and decrement the total if the box is later unchecked.

I have tried various suggestions found in the forum, to no avail.

Any suggestions?

This topic has been closed for replies.
Correct answer Matteo95

The code I provided will do that.


I have a textbox set up for error checking, called devTest.  Your code increments the value of devTest when the checkbox is checked, but doesn't decrement it (-x) when it gets unchecked.

This is the code I have in the MouseUp Event for the checkbox:

var total = this.getField("devTest").value; 

if (this.getField("chkAppInstPO_01").valueAsString!="Off")

    {total+=Number(this.getField("txtAppInstBal_01").valueAsString)}; 

this.getField("devTest").value = total;

Like I said, it increments (+x) fine.  It just doesn't decrement (-x).

1 reply

try67
Community Expert
Community Expert
November 1, 2018

Are those items text fields, or do you just want to add up fixed values based on the state of the check-boxes?

Matteo95
Matteo95Author
Participant
November 1, 2018

Each text field may have an amount (number) in it that will be added to the total, if the check box is checked, and subtracted from the total if the checkbox is unchecked.  I want to tie these computations to the checkbox actions, and then add error handling if the textbox doesn't have a value.

X  Description     Balance

x   Item here        10.00

     Item here        10.00

x   Item here        10.00

The total field should have a total of 20.00 in it, because only 2 lines are checked.  If the third one gets checked, or if any don't have a value, then the total should decrement by the corresponding amount.

try67
Community Expert
Community Expert
November 2, 2018

You can use something like this as the custom calculation script of the total field, then (adjust the field names to match those in your file, of course):

var total = 0;

if (this.getField("Checkbox1").valueAsString!="Off") total+=Number(this.getField("Text1").valueAsString);

if (this.getField("Checkbox2").valueAsString!="Off") total+=Number(this.getField("Text2").valueAsString);

// etc.

event.value = total;