Skip to main content
Inspiring
May 13, 2025 8:40 PM UTC
Answered

Check box based on value of another field

I have a checkbox that I want checked when the value is equal greater than 2500 and unchecked when below.  Trying to run a validation script but I can't figure out why this isn't working.

if (event.value >= 2500)
{
this.getField("PriceBox").value != "Off"

} else {
this.getField("PriceBox").value == "Off"
}

 

try67
try67Correct answer
Community Expert
May 13, 2025 10:54 PM UTC

This will only work if the Export Value of the check-box is "Yes". To make it independent of that you can use this code:

 

this.getField("PriceBox").checkThisBox(0, (event.value >= 2500));

6 replies

Thom Parker
Community Expert
Community Expert
May 13, 2025 10:01 PM UTC

Your code is nearly correct, assuming it's a validation script on the text field where the number value is entered. 

the problem is that you are using comparison operators, instead of assignment operators. 

Here's the fix.

if (event.value >= 2500)
{
   this.getField("PriceBox").value = "Yes"
} else {
   this.getField("PriceBox").value = "Off"
}

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 13, 2025 10:54 PM UTC

This will only work if the Export Value of the check-box is "Yes". To make it independent of that you can use this code:

 

this.getField("PriceBox").checkThisBox(0, (event.value >= 2500));

Translate
Participating Frequently
May 13, 2025 9:07 PM UTC

Try:

// this is a field level calculation script that
// goes in the AMOUNT FIELD
// Assumes PriceBox is a yes or no checkbox field

var amount = Number(this.getField("AMOUNT FIELD").value);
var checkbox = this.getField("PriceBox");

if (amount >= 2500) {
checkbox.checkThisBox(0, true); // Check the box
} else if (amount < 2500) {
checkbox.checkThisBox(0, false); // Uncheck the box
}

event.value = amount; // Optional, if the field should still show the value

Translate