Convert Radio Button Groups to Checkbox Groups in PDF Forms

If you’ve worked with PDF forms, you are probably familiar with radio buttons:

There is one problem with radio buttons: When you have a selection that also includes “non of the above”, you have to create a separate option for that: A radio button group – once selected – cannot be unselected.

Sometimes it would be useful to allow the user to unselect a radio button. This can be accomplished with a checkbox group:

A checkbox group behaves just like a radio button group (e.g. only one option can be selected), but does allow you to have all options deselected by clicking on the currently selected item.

There is no automatic way to create these checkbox groups as for radio buttons, we have to manually apply the same name to all checkboxes that we want to be part of the group (on the “General” tab of the field properties), and then provide different export values for the different checkboxes in one group. This can be done on the “Options” tab of the field properties:

The same tab also allows us to modify the style of the checkbox. To make it look more like a radio button, I usually select “Circle” as the check box style. As you can see from the screenshots above, the checkbox still has a square “box”, whereas a real radio button uses a round container, but the checkmark is now a black “dot” or circle, just like for a radio button.

If you’ve created a complex form with radio buttons, and your requirements for the form change late in the implementation phase, and all of a sudden you need to make sure that a radio button selection can be deselected, you will have to convert all radio button groups to checkbox groups.

This is may be a very cumbersome change for a complex form if done manually, but with the help of some JavaScript, we can make this change automatically with a few lines of JavaScript code.

If you run the following code in e.g. an Acrobat Action, all radio button groups will get converted to equivalent checkbox groups:

To “fine tune” this process, it would also be possible to run the conversion script only for radio buttons that have a certain name. You can do this by e.g. changing the loop in the last few lines to somehting like this:

39 Responses to Convert Radio Button Groups to Checkbox Groups in PDF Forms

Karl,
I’m not a programmer, so I’m not sure how to edit your JavaScript to convert other types of form fields. It would really help if you could give an example of how the script could be changed for other types of form fields, as in your example of changing text fields to drop down controls.

Even though this has nothing to do with the blog post, here is some information about the “Locked” property: This checkbox only locks the properties of the field when using the properties dialog. The user can easily uncheck that box and get write-access to the properties again. There is no JavaScript equivalent to this checkbox, we cannot uncheck it or check it via JavaScript. However, you can modify the field, even though it may be locked, via JavaScript.

Tucker, it looks like I missed your question when you posted it. Sorry about that. You can certainly change checkbox groups into radio buttons. When you look at the script, you should see how I am detecting radio buttons, and then getting all “widgets” for that control. You can do the same thing for widgets in a checkbox group. Just follow my example and look for widgets in a checkbox group, and then create a radio button group out of that information.

I tried to modify your script to change several Buttons in one document, all Buttons perform a mailto:xyz@abc.com, i want to change this to 123@abc.com, but i stuck. Is it possible to do this with JavaScript?

Peter, what you want to do is something completely different than to convert a group of boxes. You can add an action to a button via JavaScript (see the Field.setAction() method), but this will replace anything that was there before. This means you cannot just replace a string in an existing button action, you will have to know what was there before and recreate everything else that you may have to do when the button is pressed.

Hi There, I know this is an old article but, I tried using it and I’m getting an Syntax error; SyntaxError: syntax error
1:Console:Exec
undefined
Not sure what to do to fix it, any help would be appreciated.

Jill, I am sorry, but I don’t quite understand how your form is working. when you have radio buttons, you can only select one button at a time. So if you selected your opt-out button, you cannot select any other button without also deselecting the opt-out selection again.

Karl, I have Acrobat Pro DC (2015), I have not modified the code at all (it is exactly what I want to do), and have tried running the code from the debugger as well as attached to a temporary button placement. Thanks for the response.

Sarah, without knowing any JavaScript, you will not be able to recover if something goes wrong. In theory, you should not have to change anything, but usually, you don’t want to convert all radio button groups (and you do say “some” in your comment), so ideally, you would write a filter in JavaScript so that only those groups you want to have converted will get processed.

Dan / others; If you encounter the same issue of the “syntax error”, make sure you highlight the code within the console before executing.

Verified steps from the latest Acrobat Pro DC:
1) Open the Javascript Toolbar via Tools -> Javascripts.
2) Click “Debugger” on the toolbar.
3) In the “View” section, select “Console” in the dropdown, then paste the code from Karl in the box.
4) Highlight the code in the box, and press Ctrl + Enter on your keyboard.

Thank you for this information. I was able to successfully convert the radio button group “sources” to checkboxes using your code; however, even though the properties indicate they are checkboxes, they still act like radio buttons (i.e. when I check one and then another, the check in the first goes away). What am I missing? Thanks.

Joel, a checkbox group behaves exactly like a radio button group: Only one item can be selected at any given time. The only difference is that you can deselect all options, by clicking on the currently selected item. This is not possible with a radio button group. If you want a different behavior, you need to use different names for the individual checkboxes. Using the same name will create such a checkbox group. The script will always use a checkbox group (meaning that all buttons share the same name), but you can of course modify the script to adjust the output.

I just ran onto your blog as I was searching for a way to convert checkboxes to radio buttons, fabulous resource.

I tried running the script as written, just to see what happens, and it deleted existing radio buttons. (Trying this before trying to edit the script to do the opposite) I wonder what I’m doing wrong? Acrobat 11.

I would be glad to pay you for the script to do the conversion from checkbox to radiobutton. In addition, I’m interested in getting you to create some plugins- for example, could you create a plugin (or a script) to convert all H1 tags to H2? What about table scoping, say, scoping top row to column and left column to row, globally, for all tables in a document?

Apparently, my company does not give me permissions to edit or create Java Script 🙁
I tried doing the check boxes instead of radio buttons manually and I am not able to give them the same name/different export values as I had with my radio buttons.

Amelia, unfortunately, I don’t understand what you are asking for. Radio buttons and checkboxes should be able to be named the same way (and have the same export values). You just need to make sure that you remove your radio buttons before you add your checkboxes. You cannot have two fields with different types share the same field name.

Thank you for posting this. I have Acrobat forms form the IRS that other programs could not process because there was something unusual about the checkboxes, but modifying your script to simply replace the checkboxes with new checkboxes solved the problem. Thanks again.

Hi Karl I have this script for a stamp that I modified for my use and it has 3 radio button selection in it and i would need the script to allow me to deselect the one so none of them are selected I’ve tried to run your script but it just end up deleting all 3 radio button not sure why. Im not sure if I can post the script in this post or if I could email your the script if you could help me out that would be great.

@D: Yes, that’s possible. The tab order is different from the order in which the script processes the fields, so the newly created fields would be inserted into the tab order in the order in which they were created. This means that you save some time by not having to manually create these fields, but you need to spend (a lot less) time to update the tab order.

Thanks for your script Karl, it’s been extremely useful to help gain some insight into Acrobat scripting syntax and for making conversions across multi-page documents. Unfortunately, I have several hundred PDF Forms where text fields are getting placed by the form detection instead of check boxes. I’ve been trying to modify your script to change a “text” field into a “checkbox” field, by basically doing the same process of creating a new field type with the same name and then deleting the original.

I was wondering if you could point out what’s wrong in this particular script:

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Tip Jar

If the information you found on my site helped you to solve a problem, please consider to hire me for your next PDF related project. If you just want to say “Thank You” for the tips and tricks I provided, you can leave a tip via PayPal (starting at $1):