Skip to main content
coldcast
Participant
February 2, 2017
Answered

Form Fields -- Is it possible to do numerical calculations by adding the number of checkmarks on a page?

  • February 2, 2017
  • 1 reply
  • 676 views

I have a document which I have made editable with lots of form fields (especially checkmarks).

These checkmarks display certain options that the person can choose, and they are under their own "Category"

If 2 checkmarks are selected under that specific category, is there a way that I can have something print ON the document that says
"2  OPTIONS SELECTED " in a visually noticeable way? I understand this may take a bit of programming to achieve, but I would like to know what your thoughts are, and if there is a possibly simple way of doing this.

Thank you!

This topic has been closed for replies.
Correct answer try67

The script runs each time you make a change in the file, which is good because you want it to clear the text field if less than two boxes are ticked, no?

OK, so here's how you can do it. Use this code as the custom calculation script of your text field:

var checkboxes = ["Checkbox1", "Checkbox2", "Checkbox3"]; // replace with actual field names

var counter = 0;

for (var i in checkboxes) {
    if (this.getField(checkboxes).value!="Off") counter++;
}

if (counter<2) event.value = "";

else event.value = counter + " OPTIONS SELECTED";

1 reply

try67
Community Expert
Community Expert
February 2, 2017

Sure, it can be done with a not-too-complicated script.

The way to do it is to create a (read-only) text field and use its custom calculation script to count the number of ticked check-boxes and then populate it with the desired text.

What should happen if more (or less) than two check-boxes are ticked, though?

coldcast
coldcastAuthor
Participant
February 2, 2017

That sounds not too complicated!
If no checkboxes are selected, I wouldn't want the script to run and populate the text field. If more than 2 are selected, I would just want the formula to calculate and display the number of checked boxes.


Also, I want the formula to run only for a specific set of checkboxes. Is that too complicated?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 2, 2017

The script runs each time you make a change in the file, which is good because you want it to clear the text field if less than two boxes are ticked, no?

OK, so here's how you can do it. Use this code as the custom calculation script of your text field:

var checkboxes = ["Checkbox1", "Checkbox2", "Checkbox3"]; // replace with actual field names

var counter = 0;

for (var i in checkboxes) {
    if (this.getField(checkboxes).value!="Off") counter++;
}

if (counter<2) event.value = "";

else event.value = counter + " OPTIONS SELECTED";