Create a radio button group with javascript

Community Beginner ,
Apr 25, 2021 Apr 25, 2021

Copy link to clipboard

Copied

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

Views

247

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 25, 2021 Apr 25, 2021

Copy link to clipboard

Copied

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/

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 25, 2021 Apr 25, 2021

Copy link to clipboard

Copied

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.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 25, 2021 Apr 25, 2021

Copy link to clipboard

Copied

Thank you!

 

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

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Thank you, your suggestion worked like a charm.

Unfortunately though, I seem unable to use the same arrangement to set return values (or choices) of individual radio buttons within the same group.

I use:

this.getField("ISM.Gn.0").value="OK";

this.getField("ISM.Gn.2").value="OBS";

this.getField("ISM.Gn.3").value="NCN";

The code works but when I check, the values of the radio buttons are the default.

I must be doing something wrong....

Any help appreciated

Brgds,

Nikolas

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Use the property exportValues for this.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

If you want to set export value of radio buttons you need to use 'exportValues'.

I see you want to change 1st,3rd and 4th value, try like this:

this.getField("ISM.Gn").exportValues=["OK","","OBS","NCN"];

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

This is correct, but you can't "skip" a value. If you use that code the export value of the second field in the group will become an empty string. It will not remain what it was before...

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

It doesn't "skip" but you can't set empty export value to radio button, it revert to previous value, so if you use "" it won't change that button value. Unless I'm missing something?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

You're right. It actually does keep the old value...

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Thank you so much! I'm just a tiny bit wiser now...

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines