Skip to main content
Known Participant
July 29, 2024
解決済み

If Text Box 1 is <$10,000 and/or Text Box 2 is <10 Years Old, Text Box 3 Needs to Populate "Yes"

  • July 29, 2024
  • 返信数 1.
  • 1472 ビュー

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!!

このトピックへの返信は締め切られました。
解決に役立った回答 try67

@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"


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();

 

 

返信数 1

try67
Community Expert
Community Expert
July 29, 2024

What should happen if either of those fields is empty?

Known Participant
July 29, 2024

@try67 They shouldn't ever be empty, but if they are, Text Box 3 should say "No"

try67
Community Expert
Community Expert
July 29, 2024

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";
}