Skip to main content
Participant
May 31, 2020
Answered

Checkbox conditional on value in another field

  • May 31, 2020
  • 1 reply
  • 3923 views

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.

This topic has been closed for replies.
Correct answer Thom Parker

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.  

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
June 1, 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 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
June 1, 2020

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.

Thom Parker
Community Expert
Community Expert
June 1, 2020

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 PDFScriptingUse the Acrobat JavaScript Reference early and often