Skip to main content
Participant
October 26, 2021
Question

Assistance with PDF Calculation: Want active Checkboxes to Subtract Value from Specified Text Field

  • October 26, 2021
  • 2 replies
  • 209 views

Hey there everyone! I'm just stretching my coder wings in regards to javascript.
I've been diving deep into custom PDFs and Calculations. What I'm trying to accomplish seems simple; but I can't find the resources anywhere to help me resolve the problem. Most likely it's because I don't get know how to ask the right question.

What I'm trying to accomplish is to set up a Calculation where if a checkbox is activated (checked) then it Subtracts 1 from a specified Text (number) field elsewhere on the page. If I can get one checkbox working then I can implement the technique elsewhere and on future projects.

 

The project I'm working on may seem frivolous, but it's a very valuable and practical learning activity for me. I'm currently making a custom Character Sheet for a Tabletop RPG. I have all the other fields functioning precisely as desired; but they're all simple addition or cloning of values from other text fields.

 

So here's the situation:
I have 12 check boxes; they represent damage penalties accrued by the player. Ideally each of these checkboxes would subtract one (-1) from the "Toughness" text field's current value when they are selected.
They are all uniquely identified: "injury1" "injury2" etc through "injury12"

The text field is "defense_toughness_total" if I can figure out how to get "injury1" to subtract one (-1) from "defense_toughness_total" when it's selected (checked, active) I should be golden from there.

 

 It seems like

if (this.getField("injury1").checked = checked) {
this.getField("defense_toughness_total").value -= 1}

just isn't the way to go about this.

Any help, or guidance would be greating appreciated.

For additional reference:

 

The part of the code I'm using that works is:

  //Toughness - Base
this.getField("defense_toughness_base").value =
this.getField("sta_total").value
  //Toughness - Total
this.getField("defense_toughness_total").value = 1 *
(this.getField("defense_toughness_base").value
+ this.getField("defense_toughness_rank").value)

And I'm just at a total loss as to how to incorporate the checkbox into the mix.

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
October 26, 2021

The first step in creating such a script is always to clearly define how it's supposed to work.

So you tick the box and it reduces one from the field's value. OK. What happens when you untick it? Should it increase the value of the field by one, too? If not, each time you tick it the value will be reduced by one, making it smaller and smaller. Also, what should happen if that field is zero, or empty? etc.

Participant
October 26, 2021

I FOUND IT!!!!

For the record

if (this.getField("injury1").value == "Yes")
{this.getField("defense_toughness_total").value -= 1};

or more generally:

if (this.getField("checkbox").value == "Yes")
{this.getField("textfield").value -= 1};

More Info Here