Skip to main content
bbpatch
Participating Frequently
January 22, 2018
Answered

Setting a Checkbox Export Value to a Value in another field.

  • January 22, 2018
  • 1 reply
  • 20818 views

Hello! How might I go about setting a Checkbox's exportValue to the value placed in another text field? The value in that text field will change periodically, so I would want that exportValue to change with it.

I have a D&D character sheet that auto-sums the skill checks. The checkbox will represent if a character is proficient with said skill. So if that box is checked, I want it to add the proficiency bonus.

Thank you!

This topic has been closed for replies.
Correct answer Thom Parker

The export value is set with the "exportValues" property, but this property must be an array, cause it's used for radio buttons as well.

Put this script in the Validate script for the field that will set the check box export:

this.getField("Checkbox").exportValues = [event.value];

Don't forget to change "Checkbox" to the name of your fields

1 reply

Thom Parker
Thom ParkerCorrect answer
Adobe Expert
January 22, 2018

The export value is set with the "exportValues" property, but this property must be an array, cause it's used for radio buttons as well.

Put this script in the Validate script for the field that will set the check box export:

this.getField("Checkbox").exportValues = [event.value];

Don't forget to change "Checkbox" to the name of your fields

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
New Participant
February 12, 2020

I am having a similar issue...

 

 From: https://dnd5echaractersheet.com/wp-content/uploads/2017/10/DnD_5E_CharacterSheet-Form-Fillable.pdf 

 

 

I am trying to get the Acrobatics (Acrobatics) box to total up the Dexterity Modifier Box (DexMod) and if the check box (Check_Acrobatics) in front of it is checked, add the Proficiency Bonus (ProfBonus) for a total that can change depending on the number in ProfBonus. In this example it's a 3, so should total a 5.

The Acrobatics Box is currently using a Calculate formula that is auto generated:

 

I tried using this solution of this.getField("ProfBonus").exportValues = [event.value]; in the Check_Acrobatics check field export value:

 

But it doesn't autocalculate from a 2 to a 5 when it is checked...

 

This is exactly what the OP was asking to do, even if perhaps he didn't explain it clearly for a Non-D&D player to understand...  That when a box is checked, it change the skill (Acrobatics) based on the Stat Modifier (DexMod) plus the Proficiency Bonus (ProfBonus) if the check box (Check_Acrobatics) is checked, and just the Stat Modifier (DexMod) if the check box (Check_Acrobatics) isn't checked.  I hope I explained our problem adequately.

 

If I put a 3 in the Check Box's Field Export instead of the this.getField("Checkbox").exportValues = [event.value]; then it does give me a 2 or a 5 depending on how the box is checked or unchecked...

Thom Parker
Adobe Expert
February 27, 2020

I provided a custom javascript calculation script. It won't work in simplified field notation.

 

You need to make sure the field names are correct, but there is an error in the code. I missed referencing the field value on one place. Here's the correction

 

event.value = this.getField("DEXMod").value;

if(this.getField("Check_Acrobatics").value != "Off")

    event.value += this.getField("ProfBonus").value;

 

Whenever something related to scripting doesn't work in Acrobat, then the very first thing to do is to look in the JavaScript Console. If there's an error reported there, then tells about it when you post to the forum.

Here's a tutorial on the Console Window:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 


Sometimes JavaScript thinks the values are strings instead of numbers. In this case it concatenates the values.

Here's a redo of the script that guarantees the values are treated as numbers

 

event.value = Number(this.getField("DEXMod").value);

if(this.getField("Check_Acrobatics").value != "Off")

    event.value += Number(this.getField("ProfBonus").value);

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often