We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.
I'm creating a character sheet, and here's the rub:
I have a checkbox: Tag01
I have a Text field: Skill01
The text field can be edited by the user.
If the check box is checked, the Text field increments by 2.
The part I can't figure out is: when the check box is unchecked, that +2 bonus is removed, BUT I don't want it to continually subtract 2 from any values placed as it starts unchecked by default.
If Tag01 becomes checked: +2 to Skill01 value.
When Tag01 becomes unchecked: subtract +2 bonus to Skill01 value, but only if bonus was applied to begin with.
I hope that makes sense.
So you want to have a field that is both editable and calculates at the same time. These two things are logically incompatible. Anytime the calculation executes it use the current value in the calculation.
You can't actually have a field calc act on itself and not have wild, and possibly fatal results. But, what you can do is create the appearance of the field acting the way you want, by putting the entered value into a hidden field, then using the hidden field in the calculation.
This is tricky business.
First, create a hidden field named "HiddenValue".
Now use the committed keystrok script to save the entered value. Enter this script into the custom keystroke script for the "Skill01" field.
if(event.willCommit) this.getField("HiddenValue").value = event.value;
Now use this script in the Custom Calcualtion for the "Skill01" field
var nVal = this.getField("HiddenValue").value; if(this.getField("Tag01").value != "Off") nVal +=2; event.value = nVal;
Wow! That's a great answer! I didn't think of it that way.
I'll try this out immediately!
How is the script supposed to know if the bonus was applied or not to begin with?
What I would do is set the check-box to add 2 when ticked, and subtract 2 when un-ticked, but also set the text field to reset the check-box when its value is edited... I think that will fulfill your requirements.
How would I do that? I can make the field increment on check, but not subtract or reset.
You can use this code as the Mouse Up event of the check-box:
var f = this.getField("Skill01");
f.value += (event.target.value=="Off") ? -2 : 2;
And this as the custom validation of the text field:
this.getField("Tag01").value = "Off";
It's on the right track but I belive you need more complex string,for example what if you check checkbox and then change value in field? it won't add 2 to new value and if you uncheck it will remove 2 from new value.
Actually, that's perfectly fine. Thank you for your help.