Print Page | Close Window

Can you count selected radio groups?

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=1102
Printed Date: 22 Jan 2020 at 9:42am
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Can you count selected radio groups?
Posted By: Maki
Subject: Can you count selected radio groups?
Date Posted: 15 Feb 2014 at 11:45pm
Hi
Can I get Acro JS to return a numeric value for radio group if any of the buttons was pressed?

I'm trying to create a membership application form for a dog training club, which has fee calculation table at the end.
People applying for membership pay joining and membership fees per household and activity (course) fee per dog. The form has fields for max 6 dogs.
One activity, namely Canine Companion course, has 4 levels, which is made selectable with radio button group, and other courses are with checkboxes because these courses happen on different days and one dog can be enrolled in other activities simultaneously whereas it cannot be in different levels of Canine Companion course.

I'd like acrobat to return value 1 if any, and regardless of which, of the radio buttons of Canine Companion course is pressed.  This will be summed up at the fee calculation table as a number of dog in Canine Companion course and will be multiplied by 40 (all activity costs $40 per dog).

I've been reading John Deubert's ebooks but not well versed with JS programming. Hope someone can help.  Thank you.   Maki


-------------
Maki@Canberra, AUS



Replies:
Posted By: Maki
Date Posted: 18 Feb 2014 at 7:16am
What I'm trying to achieve is best explained in this simplified version of my form.

http://bit.ly/1e2SAj3

There are fields to enroll MAX 6 dogs, hence 6 sets of radio button group, but most people enroll only one or two dogs. 

Canine Companion class has four levels but they all cost the same ($40).  I want to populate DogCount.0 field by counting Canine Companion level (K9CompLevel) radio button group that are selected.  Which level was selected within the group is not going to be an issue.

Advanced dog sports (Agility, Flyball, Trial Obedience) classes happen on the different days of the week to Canine Companion classes, therefore they are selectable with checkboxes.

Could someone please suggest custom calculation script to go into DogCount.0 field calculation?
Many many thanks.




-------------
Maki@Canberra, AUS


Posted By: try67
Date Posted: 18 Feb 2014 at 9:52am
You can use this code as the field's custom calculation script:

var counter = 0;
for (var i=0; i<=6; i++) {
    if (this.getField("K9CompLevel_"+i).value!="Off")
        counter++;
}
event.value = counter;


-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: Maki
Date Posted: 19 Feb 2014 at 7:48am
It works great! Thank you so much!

However, can I ask one more question?

The calculation of Grand Total seems to happen always a few steps behind.
Is there a reason for this and a way to get around it?

The updated version of the form is http://bit.ly/1e2SAj3 - here .


-------------
Maki@Canberra, AUS


Posted By: try67
Date Posted: 19 Feb 2014 at 4:26pm
Yes, incorrect field calculation order.
You can set it to the right order in Form Edit mode, via Tasks - Other Tasks.


-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: Maki
Date Posted: 19 Feb 2014 at 9:24pm
Another massive thanks, Gilad!
You made my day! Hug


-------------
Maki@Canberra, AUS



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net