Skip to main content
Participant
Aug 11, 2022 7:28 PM UTC
Answered

total field for selected checked boxes

What is the correct custom script for the field suming all checked boxes (Check Box6.1, Check Box 6.2 and Check Box6.3)? Appreciate your help! I tried to read previous posts on total of check boxes but those scripts didn't work. 

This topic is closed to new replies. Start a new post to keep the conversation going.
Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
Aug 12, 2022 5:52 AM UTC

Give checkboxes export value to be 1. Now use built-in function in text field under 'Calculate' tab select 'value is the' and then pick your checkboxes.

6 replies

Legend
Aug 11, 2022 10:03 PM UTC

From your description (which is good, but please do include the actual script you write) you are trying to sum something that isn't a number. Check boxes are on or off, but they aren't something you can add up or sum. What you need to do is COUNT the boxes which are checked (by looking at each box in turn to see if it is checked). This will indeed need JavaScript.

Translate
Participant
Aug 11, 2022 10:12 PM UTC

I found this script from another post, but I wasn't sure how to add "Check Box6.1" and "Check Box6.2" to this script:

 

var total = 0;

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

if (this.getField("cb"+i).value!="Off") total++;
}

event.value = total;

Translate
Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
Aug 12, 2022 5:52 AM UTC

Give checkboxes export value to be 1. Now use built-in function in text field under 'Calculate' tab select 'value is the' and then pick your checkboxes.

Translate
Legend
Aug 11, 2022 8:24 PM UTC

Please show your last effort, so we can help you understand what's wrong, and fix it, rather than just write it for you.

Also say what type of action it is (eg mouse down, validate, calculate)

Translate
Participant
Aug 11, 2022 8:50 PM UTC

Okay, I will try my best to describe what I did. First I created two check boxes ("Check Box6.1" and "Check Box6.2") and I chose 'yes' to export value for both boxes. I chose mouse down under action for each box. Both boxes do not have the calculation option. I then created a text box to function as a total for counting all checked boxes and formated it as number with 0 decimal places . I chose mouse down for this text box ("6 #). This field value isn't validated. I tried to calculate it by having it suming both Check Box6.1 and Check Box6.2, but it didn't work. I believe I need to type a custom script to make it countable. I hope this is clear enough for you to follow? 

Translate