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
