[Webinar] Streamline your web hosting managementRegister Today


Acrobat: Advanced Radio Buttons

Posted on 2004-09-09
Medium Priority
Last Modified: 2011-10-03
I have an Acrobat numeric form field which contains a calculated value. The value is not "read only".

There are a pair of radio buttons, which toggle (same name; different export values).

When I press Button A, I want to add $3 to the value of an the numeric form field. When I press Button B, I want to add $5 to the value of the numeric field.

When the form loads, the buttons both need to be blank. Then whichever one is pressed will perform as above.

However, if the user changes his mind and selects the alternate button after already making a selection, the script has to subtract out the button being blurred before adding in the value from the button getting the focus.

Is this possible, or is there a better way to solve the problem of adding in one of two supplemental values to the numeric field?

Thank you.
Question by:goodmorals
  • 7
  • 6
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12023242
You should make the text field read-only. This only applies to changes done interactively. Because the field contains a calculated value, nobody should be able to modify the field with mouse/keyboard.

Do you want the user to be able to deselect both radio buttons/checkboxes after one was selected?

Author Comment

ID: 12026217
I have found that once I click a paired radio button that I do not know how to return both buttons to an unchecked state. I need to save the form so they are both unchecked when the user loads the form in Reader.

The user has to check one button or the other, so there is no need for the user to be able to deselect both after one has been selected.

The $3 or $5 value added into the numeric field should be subtracted out only when a button is already checked when deselected (and then the amount associated with the newly-selected button is added in its place).

Thank you again for your help.
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12028600
I've implemented this with two independent radio buttons, and two check-boxes to store a mirror of the radio button settings. This is necessary to be able to determine the previous setting (you don't want to add another $5, just because the user clicked on the radio button again.

The following document level script (select "Advanced>JavaScript>Document JavaScript..." to add this script) assumes that you have one text field named "Text1", two radio buttons named "RadioButton1" and "RadioButton2", and two check boxes named "CheckBox1" and "CheckBox2". You need to make the checkboxes "hidden", so that the are not available to the user.

function selectButton(button_nr)
    var f1 = this.getField("RadioButton1");
    var f2 = this.getField("RadioButton2");
    var f3 = this.getField("Text1");
    var f4 = this.getField("CheckBox1");
    var f5 = this.getField("CheckBox2");
    var this_button, other_button;
    var this_value, other_value;
    var this_hidden, other_hidden;

    if (button_nr == 1)    // the first button (A) was selected
        this_button = f1;
        this_value = 3;
        this_hidden = f4;
        other_button = f2;
        other_value = 5;
        other_hidden = f5;
    else                    // the second button (B) was selected
        this_button = f2;
        this_value = 5;
        this_hidden = f5;
        other_button = f1;
        other_value = 3;
        other_hidden = f4;

    var new_value = f3.value;

    // is the other button selected?
    if (other_button.value == "Yes")
        // subtract the value "other_value" and assign it to the field
        new_value -= other_value;              

        // deselect the other button and the hidden "mirror"
        other_button.value = "Off";
        other_hidden.value = "Off";

    // Is the this button un-selected (otherwise, it was already selected, and
    // we don't have to do anything). We cannot use the current button state, because
    // this is already set to "selected" (we just clicked with the mouse on it). We
    // are therefore using the hidden "mirror" of this button for this purpose.

    if (this_hidden.value != "Yes")
        // add "this_value"
        new_value += this_value;

        f3.value = new_value;

        // ... and select the mirror checkbox
        this_hidden.value = "Yes";
// end of script

Then create a JavaScript "Mouse Up" action for the first button (A) that looks like this:


and, create a JavaScript "Mouse Up" action for the second (B) button tha tlooks like this:


There is however another way to do this: You can create a calculation script that takes the input value, and the state of your (in this case group of) radio buttons and then calculates the output value whenever the state of the radio button changes, or when you do an explicit recalculation of the form. This way, the logic behind the buttons is much simpler, but you need to be able to calculate the input value (that may not be displayed anywhere on your form.
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.


Author Comment

ID: 12032244
I am wondering how to identify "RadioButton1" and "RadioButton2" in the code when they both have the same form field name, but different export values. Can you give me some guidance on distinguishing them for code purposes?

LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12033813
The reason I used to different radio buttons is that it's not possible to distinguish the different events otherwise. As I said before, if you are limited to just one radio button group, you need to use a calculation to determine the output value based on the selected radio button and the input value.

Use this as document level JavaScript:

function calculateOutputValue()
    var inputValue = ... // calculate the input value
    // var inputValue = this.getField("inputValue").value;
    var outputField = this.getField("outputValue");
    var radioButton = this.getField("RadioButton1");
    if (radioButton.value == 1)
        outputField.value = inputValue + 3;
        outputField.value = inputValue + 5;
// end of script

You need to provide a method to get/calculate the inputValue. In the commented out line, I'm just getting it from a form field named "inputValue". you can use this to experiment with the function.

This assumes that you have an output field named "outputValue", and a radio button group with two buttons named RadioButton1 that uses the values 1 and 2 as export values.

Author Comment

ID: 12046576
Thank you for your help with this matter.

I have tried out the solution and find that the radio buttons do not deselect once selected. Also, the code will permit adding $3 or $5, and then if you switch to the other button, it adds in the other amount also, and both buttons are selected. There is no subtraction of the deselected amount, or deselecting of the other button. At that point, both checkboxes are checked, and no further amounts can be added.

When the form first loads, the buttons come up both selected.

Thank you for your help in unravelling this.

The field names I am using are:

var f1 = this.getField("SC.1");
    var f2 = this.getField("SC.1a");
    var f3 = this.getField("Pymt.1");
    var f4 = this.getField("CB.1");
    var f5 = this.getField("CB.1a");

I have loaded the rest of the code into document javascript just as written.
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12049397
No, it works for me (both of them actually). Which version of Acrobat are you using (please be specific e.g. 6.0.2 Professional)?
Are you sure you used the radio buttons, and not the check boxes to make the selection?
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12049498
To reset the form (so that both radio buttons are unselected), add the following _BEFORE_ the function definition of "selectButton()" (this has to be outside of the function, so that the code gets executed when you load the document):


This will reset the form to the default values.

I just created a document from scratch, copied the code from this thread (so that any potential problems with typos in the code that I posted are caught), even used the variable names from your last comment, and it works.

Open up the JavaScript console before you load the document, then load the document, click on the radio buttons and watch for any output to the debug dialog. Do you see any error messages?

Author Comment

ID: 12052049
I uploaded the file to:


Just click on the link and it will pull up the pdf.

It is almost a megabyte so may take a little while to load.

Then you can download it to desktop and analyze.

I put the resetForm code in Recalculate01 under Document Javascript.

There are 10 lines in the form, so all the code is set up for ten uses.

However, the radio button test on the far right is only on line 1.

I have the two checkboxes visible so you can see them work.

You need to select a creditor name from the combo box and then enter a Balance Owed to create the payment field.

ALternatively you can skip this and just test the buttons without it. They will add $3/$5 to the payment field. Let me know if you experience the same problem I described. Both buttons add amounts, but don't alternate.

Thanks again for your help with this.

Author Comment

ID: 12052053
I have 6.0.1 Professional.
LVL 44

Accepted Solution

Karl Heinz Kremer earned 2000 total points
ID: 12059428
Found it. You changed the export value for the radio buttons from "Yes" to "Current" and "Past Due". The script does however check for the value "Yes", so it is not able to determine if a button is selected. This is why the "other button" does not get deselected when you click on the second radio button.

I also noticed that you could make your document level scripts a lot more straight forward: There is no need to have multiple instances of the recalculate script. Just create one, and pass a parameter into the script:

function recalculate(var ctrl)
    var balOwed = this.getField("BalOwed." + ctrl).value;
    var exportValue = this.getField("Cred." + ctrl).value;

    var newValue = Math.ceil(gPctList[exportValue] * balOwed);

    if (newValue < gMinAmt[exportValue])
        newValue = gMinAmt[exportValue];

    var f = this.getField("NewAPR." + ctrl);
    f.value = gNewAPR[exportValue];;

    f = this.getField("Pymt." + ctrl);
    f.value = newValue;

Now, when you call the script, don't call recalculate01(), but instead use recalculate(1).

You can add the this.resetForm() call to your "Global" document level script.

Author Comment

ID: 12059555
Just one question and I think we are done.

Is the export value for both buttons "Yes"? Or is there a "Yes" and a "No"?
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12059635
It's "Yes" for both buttons (it just indicates that the button is selected, I'm not using it for anything else). Keep in mind that the default values you see for a radio button are "Off" and "Yes"... not very intuitive. Every now and then, I expect to see "On" (or "No" for the "Off" state).

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to perform batch conversion of PDF, TIFF, and other image file formats into PDF, PDF Searchable, and TIFF files via a command line interface, using Nuance's latest document imaging software — Power PDF Advanced.
PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question