Copy link to clipboard
Copied
I'm trying to create a script to provide a value in a text box based on a checkbox and two other text boxes. I've been jumping between a lot of sites trying to figure it out, but no luck.
I'm using the current version of Acrobat Pro.
If the checkbox is unchecked, I want to pull the value from "Text Box_1".
If the checkbox is checked, I want to total the values from "Text Box_1" & "Text Box_2".
The results will show in "Text Box_3".
Here is what I have, but it doesn't work. Not sure where I'm going wrong.
The checkbox output is the default "Yes".
Text Box_1 & 2 will have a value of something like this: "+1" & "+3", respectively.
The result in Text Box_3 would be either "+1" or "+4" depending on the state of the checkbox.
event.value=0;
if(this.getField("Check Box_1").value!="Off") event.value=this.getField("Text Box_1").value;
else if(this.getField("Check Box_1").value!="Yes") event.value=(this.getField("Text Box_1").value + this.getField("Text Box_2").value);
Any help would be greatly appreciated.
Copy link to clipboard
Copied
Use this as 'Custom calculation script' of "Text Box_3" field:
var t1 = Number(this.getField("Text Box_1").valueAsString);
var t2 = Number(this.getField("Text Box_2").valueAsString);
var check = this.getField("Check Box_1").valueAsString;
var total = 0;
total = (check == "Off" ? t1 : t1 + t2);
if(total == 0 || isNaN(total))
event.value = 0;
else
event.value = "+"+total;
Copy link to clipboard
Copied
What exactly isn't working for you?
Are values '1' and '3' or '+1' and '+3'?
Copy link to clipboard
Copied
It won't toggle the value based on the state of the check box.
The values I'm working with (in Text Box 1 & 2) are +1 & +3.
Copy link to clipboard
Copied
I've tried this, too:
if (this.getField("Check Box_1").value!="Off") event.value= this.getField ("Text Box_1").value;
else event.value= this.getField("Text Box_1").value + (this.getField("Text Box_2").value;
Not sure what I'm doing wrong. Either argument, used on its own will work fine:
This works: event.value = this.getField("Text Box_1").value
It returns the value of Text Box_1.
This works: event.value = this.getField("Text Box_1").value + this.getField("Text Box_2").value;
It returns the sum of the values of Text Box_1 & 2.
I just can't figure out how to toggle between them based on if the check box is checked or not.
Copy link to clipboard
Copied
This gets me a result of "1" based on the first line (no + sign.)
Checking the checkbox does nothing.
event.value= this.getField("Text Box_1").value;
if (this.getField("Check Box_1").value!="Yes") event.value= this.getField("Text Box_1").value + this.getField("Text Box_2").value;
Text Box_1 = "+1"
Text Box_2 = "+2"
Copy link to clipboard
Copied
Use this as 'Custom calculation script' of "Text Box_3" field:
var t1 = Number(this.getField("Text Box_1").valueAsString);
var t2 = Number(this.getField("Text Box_2").valueAsString);
var check = this.getField("Check Box_1").valueAsString;
var total = 0;
total = (check == "Off" ? t1 : t1 + t2);
if(total == 0 || isNaN(total))
event.value = 0;
else
event.value = "+"+total;
Copy link to clipboard
Copied
Yes! You are awesome! Thank you so much for your help with this. It was driving me nuts.
Copy link to clipboard
Copied
I am greatly appreciative of you solving this for me. I was wondering if you might be able to answer one more question for me?
The values in Text Box 1 & 2 will change over time. Is there a way to have Text Box 3 automatically update the total when they do?
Using your script, I am able to update it manually by unchecking and re-checking Check Box 1.
Thank you for all of your help.
Copy link to clipboard
Copied
If you use script as 'Custom calculation script' of "Text Box_3" as I told you in my post, it will auto update result.
Copy link to clipboard
Copied
Strange. I have it entered in the Custom Calculation box (that's where I've been trying all the iterations) but it won't auto-update the total. Only if I uncheck and re-check.
Copy link to clipboard
Copied
I figured it out. I had to change the fields calculation order to put the checkbox after the text boxes.
Thank you again for all of your help on this. Wouldn't have gotten there without you.
Copy link to clipboard
Copied
Where does you use the script?
Copy link to clipboard
Copied
Thank you for reaching out. Nesa was able to solve it for me.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more