Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jan 22, 2018 Jan 22, 2018

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!

TOPICS
PDF forms
19.9K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jan 22, 2018 Jan 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
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
Community Expert ,
Feb 04, 2021 Feb 04, 2021

In the last line of his code try changing 'event.value' to 'event.target.value'.

Translate
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
Community Expert ,
Feb 05, 2021 Feb 05, 2021

Daybreak23 and Nesa, It is this simple.

 

If the values being added are numbers, then they are added, if the JS engine determines any value to be a string, then all the values are concatonated. So, since the values are concatonated, that means that the JS engine is interpreting one of the values to be a string. We know that anything that is explicitly cast as a number is a number.  As you've shown in the code posted where the two values are explicitly converted for the addition. So the explaination is, that in my code "event.value" is being interpreted as a string. 

 

This makes perfect sense because "event.value" is a special variable controlled by the Acrobat DOM, not the core JS model. Acrobat is in fact converting everything assigned to "event.value" to a string. This is new in the latest Acrobat update. It goes to show that you cannot depend on the behavior of anything controlled by the DOM, because Adobe could change it at any time without notice. 

 

The solution is to move all activity to the JS model side of things. This is a good general  practice. Never use "event.value" in the main calculation. Assign the final value to it at the end of the calculation script.   Here's the updated code. 

 

var nVal = Number(this.getField("DEXMod").value);
if(this.getField("CheckAcrobatics").value !="Off")
      nVal += Number(this.getField("ProfBonus").value);

event.value = nVal;

 

Also, Nesa, NEVER NEVER use event.target.value in a calculation. SHAME on you for suggesting such a thing. 

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

Translate
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
Enthusiast ,
Feb 05, 2021 Feb 05, 2021

And why not use something that works in this case?

Translate
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
Community Expert ,
Feb 05, 2021 Feb 05, 2021

what do you mean? The code I just posted does work.

 

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

Translate
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
Enthusiast ,
Feb 05, 2021 Feb 05, 2021

No, I mean about event.target.value, I know normaly it's not used like that, but why if it works in this case?

I'm just learning myself so if you could please explain i would appreciate it and I'm just wondering in this particular code what would be negative side to use it?

Translate
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
Community Expert ,
Feb 05, 2021 Feb 05, 2021

Because it doesn't work.  Setting the value of a calculation outside the context crossess the scripting context boundary and causes an event cascade that could very well crash Acrobat. It only works because in the specific case because the events settle out, instead of spiraling out out control. This situation is exactly point of my discussion. It works now because of a quirk in the Acrobat DOM implementation, but they could change this behavior at any time. In fact there is a high likelihood they could block changes through event.target.value in a calc event because it is incorrect by definition and has the potential to cause catastrophic failures.   SO DON'T DO IT!!

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

Translate
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
Enthusiast ,
Feb 05, 2021 Feb 05, 2021

I see, thanks for explanation.

Translate
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 ,
Feb 05, 2021 Feb 05, 2021
LATEST

"it's this simple." "never use event.value in the main calculation"."Shame on you for suggesting such a thing".

 

Dude. I know you're trying to be helpful, however this isn't really called for.
Your reply a few days ago indicated you had no reason to believe your old code with event.value in the calculation, wouldn't work. So clearly you didn't test it before replying. You should also probably should have explained why event.target.value is such a bad idea that you need to "shame" Nessa for suggesting something that works.

Cleary you know more than us, but at least be respectful about it.


Thanks for the new code, but your delivery needs some work.

Translate
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