Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Check box based on value of another field

Participant ,
May 13, 2025 May 13, 2025

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

 

TOPICS
Create PDFs , How to , JavaScript , Modern Acrobat , PDF , PDF forms
311
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
May 13, 2025 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2025 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));

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 13, 2025 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2025 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2025 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));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 14, 2025 May 14, 2025

Thank you sir.  What is the difference between comparison and assignment?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 14, 2025 May 14, 2025

Comparison operators are for comparing two values. The operators include:

>   Greater than 

<   Less than

== equals

!=  Not Equal 

 

The Assignment operator assigns a value to a varialbe

 var a = 1 + 1;

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 14, 2025 May 14, 2025
LATEST

Ah okay thank you sir.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines