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

Checkbox conditional on value in another field

New Here ,
May 31, 2020 May 31, 2020

Copy link to clipboard

Copied

Hi, I'm new to this. I have a group of 3 checkboxes ("High","Medium", and "Low") that I want checked based on the value that is calculated in another field "Total". 

If total is >= 40 then High checkbox is activated with the others off. 
If total is between 30 to 35 then Medium checkbox is activated with the others off.

If total is <=25 then Low checkbox is activated and the others off.

 

I appreciate any help with this.

 

Thanks.

TOPICS
Acrobat SDK and JavaScript

Views

1.3K

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , May 31, 2020 May 31, 2020

Do you use a calculation script for the total field? or one of the other calculation options?  

If the calculation is done with a script, then youc an add the code for setting the checkbox to the end of it. Otherwise you can make this a Validation Script on the Total field. 

 

To setup the checkboxes, they all need to have the same name ("Level" for example), so that they are all part of the same group. Each needs to have a different export value, "High", "Medium", and "Low". 

 

Whether it's the

...

Likes

Translate

Translate
Community Expert ,
May 31, 2020 May 31, 2020

Copy link to clipboard

Copied

Do you use a calculation script for the total field? or one of the other calculation options?  

If the calculation is done with a script, then youc an add the code for setting the checkbox to the end of it. Otherwise you can make this a Validation Script on the Total field. 

 

To setup the checkboxes, they all need to have the same name ("Level" for example), so that they are all part of the same group. Each needs to have a different export value, "High", "Medium", and "Low". 

 

Whether it's the calculation or validation scirpt, the code is the same.

 

if(event.value >= 40) this.getFeld("Level").value = "High";

else if (event.value >= 30) this.getFeld("Level").value = "Medium";

else this.getFeld("Level").value = "Low";

 

Note that the mid level is 30 to 40, and the low is < 30. The ranges you've specified are incomplete.  

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

Likes

Translate

Translate

Report

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
New Here ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

Thank you that worked. A follow up if I may. 
I used your script as a validation script for the "Total" field.

If Level "High" "Medium" or "Low is checked and another checkbox is checked, for now let's call it Checkbox1, I would like a value to populate in a separate text field. For example, if "High" and "Checkbox1" are checked then the value in the new text field = 4.

Also, would this script be placed in the custom format script of the new text field?

 

Thanks again.

Likes

Translate

Translate

Report

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 ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

For this type of behavior you need a to use a calculation script in the new field. Calculation scripts are run any time any field value is changed. The required values are coming from multiple sources.  The script for setting the value in the new field has to be triggered (run) on changes in the source fields. A calculation script is perfect for this. 

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

Likes

Translate

Translate

Report

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
New Here ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

I’m having trouble working this out to generate the value in the text field. Would you be able to provide me the script and the location to place it? Thanks

Likes

Translate

Translate

Report

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 ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

LATEST

So you can read about the type of calculation you need here:

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations/

https://acrobatusers.com/tutorials/conditional-execution/ 

 

Here's what your code should look like

 

var cLevel =  this.getFeld("Level").value;

if( this.getFeld("Checkbox1").value != "Off")

{// Checked case 

       if(cLevel == "High")

             event.value = 4;

       else if(cLevel == "Medium")

             event.value = ... something...;

}

else

{// Unchecked case 

}

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

Likes

Translate

Translate

Report

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