Skip to main content
Participating Frequently
February 21, 2025
Answered

How to set maximum on added check box values?

  • February 21, 2025
  • 3 replies
  • 1738 views

Need help please... 
I have 4 check boxes with values of 0,1,5,5 when I calculate and use 'maximum' it works, since I need to get "5" maximum score. 
However, on another section, I have 5 check boxes with values of 0,1,1,1,1 where I can't use 'maximum', since I need to get "3" max score. I also can't use 'sum(+)', as it will exceed "3" max when four boxes with values of "1" are selected. 

Correct answer try67

agreed, the approach just happen to work given the circumstances. will not work anymore if values of boxes are limited to lower than "5". 
I named section 3 fields as RF3-1, RF3-2, RF3-3, RF3-4, RF3-5 with values of 0,1,1,1,1 respectively.


OK, then you can use something like this as the field's custom calculation script:

 

 

var fields = ["RF3-1", "RF3-2", "RF3-3", "RF3-4", "RF3-5"];
var maxValue = 3;
var total = 0;
for (var i in fields) {
	var v = this.getField(fields[i]).valueAsString;
	if (v!="Off")
		total+=Number(v);
}
event.value = Math.min(total, maxValue);

 

 

If you need to use it multiple times I would recommend putting the code in a doc-level function, passing to it the fields array and the max value as parameters.

 

Edited: Sorry, it should be Math.min, not Math.max in the last line of code... Fixed it now.

3 replies

PDF Automation Station
Community Expert
February 21, 2025

The simplest way to do this to create the first check box in the section (in this example, call it "SEC3").  Then in form editing mode, right-click and select "Create multiple copies" and select 1 across and 5 down.  The field names will then be SEC3.0, SEC3.1 through SEC3.4.  Add the export values.  In the text field, calculation tab, select "Value is the maximum of the following fields" and only select "SEC3":

You can do the same thing for the subtotal fields.  Make 1 and call it Subtotal, right click >create multiple copies, then in the grand total field select "Value is the sum of the following fields":  'Subtotal'.

jey_5620Author
Participating Frequently
February 24, 2025

Thank you, tried this way initially. But it doesn't work with section 3 since the values of 5 check boxes are 0,1,1,1,1. choosing max will show subtotal of "1" even though 4 boxes with values of 1 are ticked. 

PDF Automation Station
Community Expert
February 24, 2025

I completely misunderstood what you were trying to accomplish.

try67
Community Expert
February 21, 2025

Are you trying to perform a calculation (if so, which one), or to limit the selection in case a maximum value has been reached? Your question is not very clear.

jey_5620Author
Participating Frequently
February 21, 2025

I need section 1's max score to be just "5" and section 3's max score to be just "3", then normally add them with the rest of the sections. 

try67
Community Expert
February 21, 2025

So just create a (hidden) text field for the total of each group (using the "maximum" option in the Calculate tab), then add up those total fields for the grand total.

PDF Automation Station
Community Expert
February 21, 2025

What is the difference between using 5 as the maximum and using 3?  I don't understand your issue.

jey_5620Author
Participating Frequently
February 21, 2025

Attached screenshot. Section 1 and Section 3 can only have a max score of 5,3 respectively. 
I need a way to limit both sections to their Max scores while being able to add the scores to the rest of the sections. 

try67
Community Expert
February 21, 2025

By "limit" do you mean prevent ticking the check-boxes, or just showing a maximum value in the calculation?