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

How to set maximum on added check box values?

New Here ,
Feb 20, 2025 Feb 20, 2025

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. 

TOPICS
Create PDFs , JavaScript , PDF forms
850
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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 21, 2025 Feb 21, 2025

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.

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 ,
Feb 21, 2025 Feb 21, 2025

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

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
New Here ,
Feb 21, 2025 Feb 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. 

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 ,
Feb 21, 2025 Feb 21, 2025

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

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
New Here ,
Feb 21, 2025 Feb 21, 2025

Not to prevent from ticking, but to limit max score of section to "5" regarless of ticking 1 and 5 for example. 

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 ,
Feb 21, 2025 Feb 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.

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
New Here ,
Feb 21, 2025 Feb 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. 

Screenshot 2025-02-21 173915.png

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 ,
Feb 21, 2025 Feb 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.

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
New Here ,
Feb 21, 2025 Feb 21, 2025

yes, mentioned that on my OP, that section 1 is fine to use "maximum" for calculation. 
However doing the same method for section 3 does not work since the values there are 0,1,1,1,1. when they tick all 1's the score will remain 1, will not even add anything up. 

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 ,
Feb 21, 2025 Feb 21, 2025

I see what you mean, although that approach for section 1 is not a very good one.

What are the names of the fields in section 3, then?

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
New Here ,
Feb 21, 2025 Feb 21, 2025

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.

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 ,
Feb 21, 2025 Feb 21, 2025

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.

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
New Here ,
Feb 21, 2025 Feb 21, 2025

A W E S O M E ! ! !
used for both sections that needs max, it works like a gem! thank you so much. 
Btw, is there a way to prevent computing delay when using invisible fields. Coz the visible Total Score show delay when clicking boxes on section 1 and 3 but not on other sections. 

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 ,
Feb 21, 2025 Feb 21, 2025

Check the fields calculation order. It's not related to them being invisible.

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
New Here ,
Feb 21, 2025 Feb 21, 2025

thanks! still have a delay, but that'll do it for today. will leave the rest some other time. Much appreciated. 

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
New Here ,
Feb 21, 2025 Feb 21, 2025

used the formula you gave to fix the delay, using sum(+) causes delay but not with JS script. Thanks again!

var fields = ["RF1_Total", "RF3_Total", "RF2-1", "RF2-2", "RF2-3", "RF2-4", "RF4-1", "RF4-2", "RF4-3", "RF4-4", "RF5-1", "RF5-2", "RF5-3", "RF5-4", "RF6-1", "RF6-2"];
var maxValue = 50;
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);

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 ,
Feb 21, 2025 Feb 21, 2025

In Prepare Form mode click More and there you will find the Set Fields Calc. Order command.

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 ,
Feb 21, 2025 Feb 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":

PDFAutomationStation_0-1740159623073.png

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'.

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
New Here ,
Feb 23, 2025 Feb 23, 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. 

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
New Here ,
Feb 23, 2025 Feb 23, 2025

Section 3 should have "3" as max score even 4 boxes are ticked with values of "1" each. 

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 ,
Feb 24, 2025 Feb 24, 2025

I completely misunderstood what you were trying to accomplish.

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
New Here ,
Feb 24, 2025 Feb 24, 2025
LATEST

no worries, have a great day ahead. 

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