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

Calculating Radio Checkboxes to show a Value

RustyWood
Registered: Mar 16 2010
Posts: 83
Answered

Hi newbie here ! This community has been very helpful so far, but now I'm stuck on an order form I'm working on.
Here's the problem..

I have a listing of participants each one can check a box partcipant_1_checkbox either 1 2 or 3

But I need to add a value to each

1 = 5.25
2 = 9.00
3 = 11.50

So far I can get the amount ordered into the total amount from each participant box eg 1 2 or 3 by using this in the custom calculation script box

var a = this.getField("partcipant_1_checkbox").value; // variable for the estimated value
event.value = a;

But i need the amount ordered to show up as a value eg 1 should be £5.25

as you can see from below ... not a clue!!!

var a = this.getField("partcipant_1_checkbox").value; if ( partcipant_1_checkbox = 1)
event.value = 5.25; //
var b = this.getField("partcipant_1_checkbox").value; if ( partcipant_1_checkbox = 2)
event.value = 9.00; //
var a = this.getField("partcipant_1_checkbox").value; if ( partcipant_1_checkbox = 3)
event.value = 11.50; //

Hope someone can help

With thanks
Rusty

jimhealy
Team
Registered: Jan 2 2006
Posts: 146
var a = this.getField("partcipant_1_checkbox").value;if(a == 1)event.value = 5.25; // else if (a == 2)event.value = 9.00; // else if (a == 3)event.value = 11.50; //  // set default value here if one of these may not happenevent.value = 0;

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

RustyWood
Registered: Mar 16 2010
Posts: 83
Thanks loads Jim

Thats exactly what was needed, obviously I was completely off track with my attempts I'll keep trying though!!!!

Thanks Again
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Some basics about check boxes.

1. The box can be checked or unchecked by a mouse click or space bar press.
2. A group of check boxes forms an 'exclusionary' group
3. Each check box in an exclusionary group should have unique value
4. If a check box in an exclusionary group is checked only boxes with the value of checked box will be selected.
5. Check boxes have a value of "Off" when all are not selected.

Let's look at your code that works with comments:
// get the check box object for the 'participant_1_checkbox' objectvar a = this.getField("partcipant_1_checkbox");// set the value of this field to the value of the 'participant-1_checkbox'event.value = a.value;

Note that the 'set' operator is '='.

One of the equality operators is '=='. So one could use:
// value if 'Off' or not an expected valueevent.value = 0; // set default value// get the 'participant_1_checkbox' field objectvar oCheckBox = this.getField("partcipant_1_checkbox");// check the value of the field objectif ( oCheckBox.value  == 1)event.value = 5.25; // set field value if (oCheckBox.value == 2)event.value = 9.00; // set field value if (oCheckBox.value == 3)event.value = 11.50; // set field value

Now if you assign the monetary value to the check box and then use the not equal operator, '!=', then your code could be simplified to:
event.value = 0; // set default value// get the 'participant_1_checkbox' field objectvar oCheckBox = this.getField("partcipant_1_checkbox");// test if not 'Off' valueif(oCheckBox.value != 'Off") {event.value = oChekcBox.value;}

Not the default value is set at the start of the script. This will result with the field value only being updated when a known value or an expected value is found and not forced unconditionally at the end of the script.

George Kaiser

RustyWood
Registered: Mar 16 2010
Posts: 83
Thankyou for all your information, very very helpful indeed. I'm completely new to Java Script so it is starting to sink in slowly.

I'm using a exclusionary group of radio buttons for each participant 1 2 & 3. After the third radio button value of £11.50 (which now works thanks to you guys) there is another box in which the participant add an additional order of 1 to as many as they like @ a value of £3.00 each but only if they have checked radio box 3 @ 11.50. Is there a way of setting this box so no number may be added untill check box 3 has been checked.Thank you in advance

Rusty