9 Replies Latest reply on Nov 14, 2013 1:25 PM by mjleavitt01236541

# help with custom calculation/check boxes

Hi.

I'm trying to tie checkboxes to an aggregate point total as follows:

Question1 []Yes []No

Question2 []Yes []No

1 point if either "Yes" is selected. (Max of 1 point only)

Question3 []Yes []No

Question4 []Yes []No

2 points total for each "Yes". (Max of 4 points)

I've set each checkbox to an export value of 1.

I have a tally box "box2"

```// first section questions
// set vars
var points = this.getField("YesOne").value + this.getField("YesTwo").value;
// if then
if ((points > 0)) {this.getField("box2").value = 1}
else {this.getField("box2").value = 0};
```

I've gotten stuck on the first part, as It's not working as I stated above, any help would be appreciated.

I'm trying to post the actual PDF, but I can't find a way to put it into this posting...

thanks!

• ###### 1. Re: help with custom calculation/check boxes

I've found what I think to be a bad code solution, any addtional help would be appreciated:

// set vars

var points = this.getField("YesOne").value + this.getField("YesTwo").value;

// if then

if ((points == 2)) {this.getField("box2").value = 1}

else if ((points == 'OffOff')) {this.getField("box2").value = 0}

else if ((points == '1Off')) {this.getField("box2").value = 1}

else if ((points == 'Off1')) {this.getField("box2").value = 1}

else {this.getField("box2").value = 0};

• ###### 2. Re: help with custom calculation/check boxes

Instead of using the + operator on the value property, use the isBoxChecked method.

• ###### 3. Re: help with custom calculation/check boxes

Are you using exclusionary groups for your field names?

So for each question you have 2 fields with same name. This will allow only one check box for each question to be checked at a time or none.

Are you setting the export value  value for each individual field to the value you want to be accumulated?

Question 1 & 2 have a yes  value of 1 and a no value of 0.

Question 3 and 4 have a yes value of 2 and a no value of 0.

You can then use the "Field is the ____ of fields:" to sum the check boxes, use the simplified field notation and sum the field names, or write a custom JavaScript calculation and check for field values not equal to "Off".

• ###### 4. Re: help with custom calculation/check boxes

I'm novice writing this, I'm not even sure what an "exlusionary group" is. I will google that.

the problem I've had is with the first section is how the points are tallied:

• Yes and No = 1 point
• No and Yes = 1 point
• Yes and Yes = 1 point
• No and No = 0

So I'm having issue with adding values.

How do you set the "no value to 0" - I've only been able to set the export value.

Can you expand on this a bit? Sorry if I'm too novice here.

Question 1 & 2 have a yes  value of 1 and a no value of 0.

Question 3 and 4 have a yes value of 2 and a no value of 0.

You can then use the "Field is the ____ of fields:"

thanks,

Mike

• ###### 5. Re: help with custom calculation/check boxes

Do you have an example of the isBoxChecked syntax? Sorry, I'm really new at this.

thanks,

Mike

• ###### 6. Re: help with custom calculation/check boxes

Have a look at the API Reference. There are examples there.

• ###### 7. Re: help with custom calculation/check boxes

I was hoping for some additional assistance.

Have a look at the API Reference. There are examples there.

• ###### 8. Re: help with custom calculation/check boxes

Here is an example with all 3 approaches and displaying the value of each field:

Sum Check Boxes

• ###### 9. Re: help with custom calculation/check boxes

Thanks!