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

Defining Variables and Radio Button Syntax

FlintlockFreedom
Registered: Mar 15 2011
Posts: 4
Answered

I'm new to Adobe Acrobat and am stuck on a problem. I have an evaluation form with groups of radio buttons that require a rating on a scale of 1 to 4, and at the bottom I need to total the number of 1's, 2's etc. I thought the way to do this might be to define a variable, say Total1, and have it add each Choice1 that is selected from the Radio Button Groups to create the total. My problem is I don't know where I would define this variable at and I would need four If Then statements for each group of radio buttons, which makes me think there might be an easire way to do it. Any advice or guides on using javascript in Acrobat would be awesome.
Thanks!

My Product Information:
Acrobat Standard 10.0.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Accepted Answer
The fields that show the totals would be calculated fields, so in each of the calculation scripts, you would simply get the value of each radio button group, and if the value corresponds to the field (total1, total2, etc.), add 1 to the running sum, something like:

  1. // Custom Calculate script for Total1 field
  2. (function () {
  3.  
  4. // Initialize
  5. var sum = 0;
  6.  
  7. // Count the 1s
  8. for (var i = 1; i < 11; i++) {
  9. if (getField("radio" + i).value == 1) sum += 1;
  10. }
  11.  
  12. // Set this field value to the sum of 1s
  13. event.value = sum;
  14.  
  15. })();
This assumes the radio button groups are named "radio1", "radio2", ..."radio10", and that button values are 1, 2, 3, 4, so modify to fit your situation.

For the next total field that counts the 2s, change the line to:

  1. if (getField("radio" + i).value == 2) sum += 1;
etc.


FlintlockFreedom
Registered: Mar 15 2011
Posts: 4
Thanks George, that was exactly what I was looking for!
Tekexpert
Registered: Mar 31 2010
Posts: 18
HI Flintlock, Can I see the PDF in which you have applied this scripting.
Let me know how I can reach you