Skip to main content
December 11, 2025
Question

Text box script

  • December 11, 2025
  • 2 replies
  • 352 views

I am very new to coding and only know a few basics. I have a text box that adds or subracts 1 based off of another text box, which I got working well. But I also need it so other people can leave the text box blank without having to alter the number from the that it is add/subtracting from. Please see below.

 

var gravesite = this.getField("Gravesite").value;
var section = this.getField("IntermentSection").valueAsString;

if (section == "3A" || section == "3E" || section == "3J" || section == "3T" || section == "3Y" || section == "3Y" || section == "5B" || section == "5C" || section == "5D" || section == "5E" || section == "5G" || section == "5H" || section == "5I" || section == "25" && gravesite > "0") {
event.value = gravesite - 1;
}
else if(gravesite > "0") {
event.value = gravesite + 1;
}
else {
event.value = " ";
}

2 replies

try67
Community Expert
Community Expert
December 12, 2025

In addition to the good advice given above, you need to add an extra pair of parentheses to the if-condition, like this:

 

if ((section == "3A" || section == "3E" || section == "3J" || section == "3T" || section == "3Y" || section == "3Y" || section == "5B" || section == "5C" || section == "5D" || section == "5E" || section == "5G" || section == "5H" || section == "5I" || section == "25") && gravesite > 0)

PDF Automation Station
Community Expert
Community Expert
December 12, 2025

First, you should remove the quotes around the 0's (eg. gravesite > "0").  The quotes turn a number into a string.  It works in this case because the JavaScript engine will interpret it as a number but doing this might give problems in a different context when using a number comparative.  Calculation scripts run every time any field value changes so a calculated field will always revert to the calculated value after a user enters a value in the field.  If you want to avoid this and allow users to change to value, you can use a validation script in the IntermentSection field instead.  You can use the same script but change this.getField("IntermentSection") to event, and change event to this.getField("[the name of the field]").  Here's a reference for Calculation vs. Validation scripts:

https://pdfautomationstation.substack.com/p/calculation-vs-validation-scripts

Another method is to put restrictions on your script so it only calculates if the values of the fields in the calculation change:

https://pdfautomationstation.substack.com/p/another-method-for-calculation-vs

December 15, 2025

I unfortantely cannot read the articles due to a pay wall, is there anyway you could elaborate or provide an example? If not I fully understand.

PDF Automation Station
Community Expert
Community Expert
December 15, 2025

You can sign up for a free subscription then unlock one of the articles for free.  The explanation above describes how to change it to a validation script, which would go in the IntermentSection field.  There's a validation tab in the field properties.