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

Calcuclation Script Help

kentwatchlight
Registered: Feb 13 2009
Posts: 30
Answered

I have two fields, both with constant unchangeble values:

TEXT1: 35.00
TEXT2: 107.40

I have a check box:

X -Do you want a yard sign?

I have three yard sign options (radio buttons):

1 sign - $12

2 signs - $25

3 signs - $35

I want to do two things:
1) I want to set up the check box so that, when it is checked, the three yard sign radio buttons become available, and if it is then unchecked, the radio buttons disapeer again. I can't seem to get them to disapeer once they appear with a click on the check box. Even if I uncheck the box, they are forever visible after the first check. This is important because:

2) I want to calculate to a third TEXTBOX the value of TEXT1 + TEXT 2 + Value of RadioButton1 (which ever one is picked). However, I want the radio button value to be calculated with the total ONLY IF the check box is checked.

Is this possible? How do I do it?

Thank you.

My Product Information:
Acrobat Pro 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Sure it's possible. For #1, can you show us the code that you've tried?

For #2, you could do something like the following for the custom calculation script:

(function () { // Get the text field values, as numbersvar v1 = +getField("TEXT1").value;var v2 = +getField("TEXT2").value; // Get the radio button valuevar v3 = getField("RadioButton1").value; // Set the value to zero if no radio buttons are selectedif (v3 === "Off") v3 = 0; // Get the check box valuevar v4 = getField("Checkbox1").value; // Perform the calculationif (v4 !== "Off") {event.value = v1 + v2 + v3;} else {event.value = v1 + v2;} })();

George
kentwatchlight
Registered: Feb 13 2009
Posts: 30
For number one, I just used the Actions Property box for the check box to designate Show/Hide for the radio buttons.

Starting status:

Check box empty. Radio buttons hidden.

User interaction:

Check box checked; radio buttons appear.

Check box UNchecked, radion buttons disapeer.

So I have an action: Mouse Down on on check box
resulting action: radio buttons appear

However, if user then UNchecks check box, radio buttons still visible. I tried adding a second Mouse Down action; w/ resulting action: radio buttons disapeer, but then they will not appear at all.
There is no "Mouse Click" option in actions, to just turn the corresponding radio buttons on or off.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You will need to use JavaScript for #1. A Show/Hide field action does not behave as a toggle, it either shows a field or hides a field, depending on which you specify. Here is what I would do in the Mouse Up (not Mouse Down) event of the check box:

(function () { // Get a reference to the radio button fieldvar f1 = getField("Radio Button1"); // Reset the radio button fieldf1.value = f1.defaultValue; // Show/Hide the radio buttons based on the state of this checkboxf1.display = (event.target.value !== "Off") ? display.visible : display.hidden; })();

Replace "Radio Button1" in the code above with the name of your radio button field.

George
kentwatchlight
Registered: Feb 13 2009
Posts: 30
That worked like a charm. Thank you.
kentwatchlight
Registered: Feb 13 2009
Posts: 30
Spokwe too soon. The toggle function for the checkbox/radio buttons works fine, but the calculation script is not working.

Strangely, if I just do a simple sum calculation; Radio Button 4, Text5, Text6, it works great in preview mode but does nothing when saved with extended features to adobe reader. No calcs are made, it just adds text 5 & 6 and ignores anything going on with the radio buttonsSame with the above script. No affect on the text 5 & 6 calculations, regardless of checkbox or radio button selection.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
If you are free to email the form, I'd be happy to take a look.
kentwatchlight
Registered: Feb 13 2009
Posts: 30
Sent. Thank you.