These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Checkbox or Radio Button Caculation

dlee1
Registered: Oct 11 2007
Posts: 5
Answered

I'm a newbie to LC Designer and I love it. I'm pretty good at designing forms. I just don’t know javascript or formcalc at all! I use the forums and knowledge base which has been a great help. I have two challenges I don’t know how to resolve. I've experimented a lot to no avail.

I have two kinds of assessments/questionnaires in L C Designer 8 that I have created where I need some calculations done. One assessment is using yes or no answers. I need to add up all the no’s and yes’ in a respective totals field. I can use a check box or a radio button whichever is easier in terms of scripting.

The second assessment also has checkboxes. A user has to choose one word from a set. There are 9 words and 45 combinations. For example, Achievement or Recognition; Recognition or Power; Creativity or Service. At the end of the assessment, I have a Totals box for each word and I need to add up all the time the word is selected.

Any help would be so appreciated.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Both of these situations use a similar technique. The codes needs to check the value of each Checkbox or Radio button, and then increment a counter based on the value. Here is a very straight forward, but long, way to do it in JavaScript. The code assumes that the checkboxes are in the same subform as the calculation field.

// calculation script for text field
var count = 0;
if(check1.rawValue == 1)
count++;

if(check2.rawValue == 1)
count++;

... etc.

The code could be much shorter and more flexible if the checkboxes are the only fields in a subform, i.e., the subform groups all the checkboxes together. This code is written for a calculation field that's at the same heirarchy level as the subform that contains the checkboxes, named "MyCheckGroup".

var count = 0;
var checkNodes = resolveNodes("MyCheckGroup.*");
for(var i=0;i

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

dlee1
Registered: Oct 11 2007
Posts: 5
This is super!!! Thank you so much. Wow, it looks like it's just about there. I'm using the second script with checkboxes. I had to put all of the no checkboxes in one subform and the yes' in a second subform so they didn't all add up together.

One issue remains. If I check the No checkboxes or Yes checkboxes they add up in the appropriate Total fields, however when I deselect them, it subtracts them except for 1. It leaves a 1 in the total even when they are all deselected.

Any ideas?

Debi
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Place "count;", all by itself, as the very last line of the script. This will ensure that the calculation value is correct.

Like this:

var count = 0;
var checkNodes = resolveNodes("MyCheckGroup.*");
for(var i=0;i

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

dlee1
Registered: Oct 11 2007
Posts: 5
I just can't thank you enough. This script works on both the of the forms.

Thank you so much!!