Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thank you, Thom,
I appreciate your response. I have placed that script in the Validate script for the "PROF" field. I am still unsure of (and new to) the array property in JavaScript. Attached is a screenshot of a portion of the sheet. Hope this helps visualize what I cannot verbalize correctly.
I basically am just focusing on the very first skill in the Skill Proficiency table, "Acrobatics". Once I figure out the scripts and things, I will complete the rest of the skills. I'm sure I may have to rename some checkboxes and fields, as well.
Copy link to clipboard
Copied
Is this another question? Or is there something about my answer you don't understand?
Please be clear.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
My apologies, Thom.
As suggested, I have the following script in the Validate script for the "PROF" field.
this.getField("Checkbox").exportValues = [event.value];
Where do I find the "exportValues" property for the Prof Bonus checkbox, and then what would that array look like in terms of code to add the value in "PROF" when the checkbox is checked?
Copy link to clipboard
Copied
The export value of a check box or radio button is set from the Field Properties dialog, shown below.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Great, thank you! How do I put in the property as an array to add whatever value is in my "PROF" field when the checkbox is checked? Would the array code look a certain way?
Copy link to clipboard
Copied
I've already provided you with the code you asked for. What ever value is entered into the "Prof" field will be set as the export value of the checkbox. When you asked specifically about export values I assumed you knew what an "Export" value is in relation to a checkbox.
So to be clear, the export value is the value of the checkbox when it is checked. This is the same value returned by this.getField("checkbox").value. This has nothing to do with arrays in JavaScript. The array bit I described above is only for setting the export value. The data in a checkbox value is a string.
What happens when the check box is checked is a completed different issue from the bit where the export value is set. What is it you want to happen when the check box is checked?
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
When the checkbox is checked, I would like the Total to include the values in Ability Bonus, Expertise Bonus, and the value in the PROF field.
I already havethe Total field calculating the sum of all 3, however the sum doesn't change when the checkbox is checked.
Thank you for your continued support and patience.
Copy link to clipboard
Copied
The scenario you implied in your initial question was that the checkbox value would be used in the calculation. Otherwise, why would you set the export value? What you've just suggested is that you want the checkbox to gate the values used in the calculation. This is a completely different approach.
Please read this article:
https://acrobatusers.com/tutorials/conditional-execution
And here is even more info on calculations:
Calculating field values and more
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Where do you use a checkbox?
Copy link to clipboard
Copied
The checkbox is the box in the "Prof Bonus" column under "Skill Proficiencies"
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
First, you can't put code in an export value. The export is static.
However, rather than changing the export value of the checkbox, use it to conditionally modify the calculation.
event.value = this.getField("DEXMod").value;
if(this.getField("Check_Acrobatics").value != "Off")
event.value += this.getField("ProfBonus");
I don't know if I got your field names correct, but this is the process you want to use.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
If I'm understanding you correctly, I should return the (Check_Acrobatics) field Properties -> Options -> Export Value to Yes.
Then I am supposed to be able to just cut and paste that calculation into my (Acrobatics) field's "Simplified field notations" or "Custom calculations script"?
If so, it doesn't appear to be working in either Simplified or Custom, so I'm assuming I didn't do something correctly... Or misunderstood where I was supposed to make entries...
Copy link to clipboard
Copied
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
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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);
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Hi Thom,
I am trying to do the exact same thing as both the OP and Steon, however the latest code you provided was still giving me trouble. (I am fairly new to Acrobat so I wouldn't be surprised at all if the issue was on my end.)
When I use the latest code you posted on Feb 26, 2020 in the Custom Calculation Script rather than adding 2+4 for a total of 6, the "Acrobatics" field (using Steon's field names for simplicity) displays 24. Based on your last post, it appears to be concatenating rather than processing a sum total. Would you have any updates or tips for fixing this issue?
Cheers!
Copy link to clipboard
Copied
Cancel That. I found a solution!
Copy link to clipboard
Copied
What was the solution? Asking for a friend.
Copy link to clipboard
Copied
The calculation is adding the numbers as if they were strings. The solution is to explicitly convert them to numbers, as shown in my last post.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Hi Thom,
I am the friend Default is referencing.
We are asking for MrBlonde87's solution, because I am experiencing the same concatenating issue with your last post. Your last post concatenates the values. So either the Number() which should work isn't or something is missing from the actual calculation to add event.value and the number.
I've tried switching Number() to parseInt() and parseFloat() to no avial.
Copy link to clipboard
Copied
So, I figured something out but I have no idea why this works. And why Thom's last post doesnt.
event.value = Number(this.getField("DEXMod").value);
if(this.getField("CheckAcrobatics").value !="Off")
event.value = Number(this.getField("DEXMod").value) + Number(this.getField("ProfBonus").value);
Copy link to clipboard
Copied
Thom's code is working fine except his code is concatenates values while your code is suming them, for example if you have values of 2 and 3, your code will show 5 while thom's will show 23, also why it doesn't work for you is probably because your field is named 'CheckAcrobatics' while in Thom's code it's 'Check_Acrobatics'.
Copy link to clipboard
Copied
I know. He just seemed so confident that his shouldn't concatenate.
also. yes i changed that field name to match mine.
My only problem is that im about to add another button and hopefully i can do it. Im just curious to understand why Thom's code "didn't" do the math.


-
- 1
- 2