Skip to main content
Participating Frequently
April 11, 2024
Question

checkbox counter

  • April 11, 2024
  • 3 replies
  • 1127 views

I am trying to create a total box to count the number of check boxes that are checked off. If a box is checked add 1 to total. if check box is unchecked remove one from the total. I have been having a little trouble getting it to work.

 

check boxes are named C 1 to C 25

 

var total = 0;

for (var i=1; i<=25; i++) {

    if (this.getField("C "+i).value!="Off") {

          total++;

    }

}

event.value = total;

 Thanks

R

 

 

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
April 11, 2024

You don't need to use JavaScript for such a simple calculation.

Set all checkboxes value to 1 and use "Sum" in the calculation.

See attachment.

Acrobate du PDF, InDesigner et Photoshopographe
Nesa Nurani
Community Expert
Community Expert
April 11, 2024

Where did you put script?

ls_rbls
Community Expert
Community Expert
April 11, 2024

Hi @GravityratRob ,

 

The script is working on my end.

 

Can you describe in a little more detail what is not working for you?

 

The comparisson operator " = " is the only thing that I noticed. 

 

Since the script is taking the string value "Off" from the checkboxes , it should be expressed as  " !== " (not equal value or not equal type),  instead of using " != " (not equal, which expects a numerical value).

 

But in either case it worked on my end.

 

Are the checkboxes field names spelled exactly as C1, C2, C3, C4... etc. ?

Participating Frequently
April 12, 2024

I found a random space!!! thanks Folks