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

Adding Variable Radio Buttons in a list

RustyWood
Registered: Mar 16 2010
Posts: 83
Answered

Hi I'm having trouble trying to add the values of each group of radio buttons together for a total from each in a list of 17. The value of the partcipant_1_checkbox shows up fine but i'm unable to get a result if I add more. I have tried numerous ways, with just 2 sets.

var a = this.getField("partcipant_1_checkbox").value;
if(a == 1)
  event.value = 1; // 
else if (a == 2)
    event.value = 2; // 
else if (a == 3)
    event.value = 3; // 
 
 
 
var b = this.getField("partcipant_2_checkbox").value;
if(b == 1)
  event.value = 1; // 
else if (b == 2)
    event.value = 2; // 
else if (b == 3)
    event.value = 3; // 
 
event.value = (a + b);

With Thanks
Rusty

My Product Information:
Acrobat Standard 9.0, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
What's the point of the entire if-else section? Just use:
var a = this.getField("partcipant_1_checkbox").value;var b = this.getField("partcipant_2_checkbox").value;event.value = a+b;

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

RustyWood
Registered: Mar 16 2010
Posts: 83
Thanks

Because each group of radio buttons have a value of 1 2 or 3 I had already tried that calculation and it didn't work

Thanks again

Rusty
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Be more specific. What happens exactly? Do you get error messages in the console? Did you set the export values for the different radio-buttons?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

RustyWood
Registered: Mar 16 2010
Posts: 83
Quote:
Be more specific. What happens exactly? Do you get error messages in the console? Did you set the export values for the different radio-buttons?
Yep I set the button groups values to 1 2 & 3 on each check box in the listI seem to be getting error 


2:Field:Calculate
this.getField("partcipant_2_checkbox") has no properties


Thanks
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You probably misspelled the name of the field. Double-check it.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

RustyWood
Registered: Mar 16 2010
Posts: 83
Exactly thats it !!!

How did you work that out so quickly, it's been killing me all day..

That's why I started all that if nonsense

Thanks Loads

Rusty
try67
Expert
Registered: Oct 30 2008
Posts: 2398
An experienced programmer can learn a lot from the error message. That's why it's important to provide all relevant details when asking for help.

By the way, you can combine all the values of the check boxes with a loop, if they have a similar name, like so (make sure to change the name of the field...) :
total = 0;for (i=1; i<=17; i++) {total += this.getField("partcipant_"+i+"_checkbox").value;}event.value = total;

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

RustyWood
Registered: Mar 16 2010
Posts: 83
Cheers, but you lost me a bit there in the loop !?

On the other calculation (which is great for me with my limited scripting) i'm getting "offoff" showing up in the the total box when nothing has been checked, I put in event.value = 0; thinking this show up as a 0 instead but no luck..



event.value = 0;var a = this.getField("partcipant_1_check_box").value;var b = this.getField("partcipant_2_check_box").value;event.value = a+b;//

Thanks again Rusty
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The loop uses the value of a variable (i) to access all the fields.
You might need to change it to something like this:
if (this.getField("partcipant_"+i+"_checkbox").value!="off")total += this.getField("partcipant_"+i+"_checkbox").value;

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

RustyWood
Registered: Mar 16 2010
Posts: 83
Hi

The problem I'm getting with this calculation

var a = this.getField("partcipant_1_check_box").value;var b = this.getField("partcipant_2_check_box").value;event.value = a+b;//

Is that it is adding all of the check boxes into one total, I need to add all the checks in column 1, column 2 and column 3 into separate totals that's why I started trying to use the statement "if"

any ideas ?

With thanks

Rusty
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Sorry, I don't understand which columns you're talking about. I will need to see the file if you want more help.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com