Copy link to clipboard
Copied
Good morning!
I have a PDF I am working on that has a section with 3 text boxes. Text Box 1 is current balance in currency. Text Box 2 is Model Year. Text Box 3 the user types "yes/no". What I am needing is Text Box 3 to auto-populate with "Yes" or "No" based off Text Box 1 and 2. If Text Box 1 is less than $10,000, Text Box 3 needs to auto populate "yes". If Text Box 2 is less than 10 years old(from the year populated in Text box 2), Text Box 3 needs to auto populate "yes". If Text Boxes 1 and 2 are both less than $10,000 and less than 10 years old, Text Box 3 needs to auto populate "yes". If neither Text Box 1 or 2 are less than $10,000 or less than 10 years old, Text Box 3 needs to auto populate 'No"
Thanks for the help!!
Copy link to clipboard
Copied
Ah, I thought the second field contains an age, not a year. That complicates things a bit... Try this:
var v1 = this.getField("Text Box 1").valueAsString;
var v2 = this.getField("Text Box 2").valueAsString;
if (v1=="" || v2=="") event.value = "No";
else {
if (Number(v1)<10000 || (new Date().getFullYear()-Number(v2))<10) event.value = "Yes";
else event.value = "No";
}
Just be aware this won't update automatically when you open the file. So if you enter "2015" now it will show "Yes", but won't change by itself to "No" if you open the file next year. You will need to force a recalculation to do that. One way is to add the following command as a doc-level script:
this.calculateNow();
Copy link to clipboard
Copied
What should happen if either of those fields is empty?
Copy link to clipboard
Copied
@try67 They shouldn't ever be empty, but if they are, Text Box 3 should say "No"
Copy link to clipboard
Copied
They can always be, and you have to take it into account.
Try this code as the custom calculation script for Text Box 3:
var v1 = this.getField("Text Box 1").valueAsString;
var v2 = this.getField("Text Box 2").valueAsString;
if (v1=="" || v2=="") event.value = "No";
else {
if (Number(v1)<10000 || Number(v2)<10) event.value = "Yes";
else event.value = "No";
}
Copy link to clipboard
Copied
@try67 It works perfectly except if Text Box 2 (Model Year) is < 10 years old and Text Box 1 (Current Balance) is >$10,000 it populates "No" for Text Box 3 (10/10 Rule Check) when it should be "Yes". So if the Balance and/or the Model year is <$10,000/10 years old, Text Box 3 (10/10 Rule Check) should say "Yes"
Copy link to clipboard
Copied
Ah, I thought the second field contains an age, not a year. That complicates things a bit... Try this:
var v1 = this.getField("Text Box 1").valueAsString;
var v2 = this.getField("Text Box 2").valueAsString;
if (v1=="" || v2=="") event.value = "No";
else {
if (Number(v1)<10000 || (new Date().getFullYear()-Number(v2))<10) event.value = "Yes";
else event.value = "No";
}
Just be aware this won't update automatically when you open the file. So if you enter "2015" now it will show "Yes", but won't change by itself to "No" if you open the file next year. You will need to force a recalculation to do that. One way is to add the following command as a doc-level script:
this.calculateNow();
Copy link to clipboard
Copied
@try67 Hmmm it still seems to be showing Text Box 3 (1010 Rule Check) as "No" when Text Box 2 is <10 years old.
Copy link to clipboard
Copied
2024 - 2004 is not < 10
Copy link to clipboard
Copied
@Bernd Alheit @try67 AAhhhhhh my apologies! It needs to be >10 years
Copy link to clipboard
Copied
Just change the < operator in that part of the code to > , then.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now