Skip to main content
Inspiring
May 13, 2025
Answered

Check box based on value of another field

  • May 13, 2025
  • 2 replies
  • 784 views

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

 

Correct answer try67

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

2 replies

Thom Parker
Community Expert
May 13, 2025

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

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
try67Correct answer
Community Expert
May 13, 2025

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

Participating Frequently
May 13, 2025

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