Skip to main content
Known Participant
April 25, 2021
Question

Create a radio button group with javascript

  • April 25, 2021
  • 2 replies
  • 4332 views

Hello to all members.

I am trying to create a report form with a LOT of radio button groups (80 groups with 6 choices each).

Some of the radio buttons will also have a script attached.

My problem is that as the number of radio buttons increases, so is the time required to rename, group and adjust the new fields in the form. So I decided to write a small script to create these radio button groups for me. The script reads information from a field already created manually and builds the required sets of radiobutton groups (or so I believe...)

The script works fine, in the sense that the new groups are created as expected in terms of name and position.

I am having issues however with the following:

- assigning the border color (can't seem to find the proper function to do that);

- assigning a separate style for each of the radio buttons in the same group (f.style=style.xx works but it applies the same style to all created buttons of the group, not to the one I want);

- assigning a custom return value to some of the radio buttons (I use f.value="some value" which is ignored and I get default values like Choice1, Choice2 etc)

- finally, setting the name of the group seems impossible (something that can be done manually, when you select all buttons within the group)

To clarify further , the individual groups (ISM.G1, ISM.G2, ISM.G3 and so on) are created by giving the same name to each radio button . While each radio button is operational within the proper group (as expected) it seems that I cannot access each radio button individually in order to alter its properties as I wish.

Because of this, after all required radiobuttons and groups are created, I go back and edit each option manually in order to get the desired results.

Is there a way to do this with javascript? I believe naming the buttons must be the key but I just can't figure it out...

Any help or guidance welcome and much appreciated.

 

Thanks in advance,

Nikolas

 

P.S.I have attached a txt file with my code (it fires when a button is pressed) and a screenshot of how the radiobutton groups are expected to look like

    This topic has been closed for replies.

    2 replies

    try67
    Community Expert
    Community Expert
    April 25, 2021

    Just like that the period in the field name is used to group fields together, it's also used to indicate individual "widgets" in a group. For example, to access the first widget in a group called "ISM.G2" you can use "ISM.G2.0" as the field name when calling getField. Then "ISM.G2.1" to access the second field (based on the order of creation), etc.

    Note, though, that some properties are shared by all the widgets in the group. So, for example, if you set "ISM.G2.0" as read-only, it will affect the entire group. But if you set its fill color to red, it will only affect that one widget.

    Known Participant
    April 25, 2021

    Thank you!

     

    As always, the simplest answers are the hardest to find...

    Known Participant
    April 25, 2021

    Apologies for the omission...

     

    I am using Acrobat DC Pro

     

    Moved from Using the Community (which is about the forums) to the correct forum... Mod
    To ask in the forum for your program please start at https://community.adobe.com/