Skip to main content
Participant
May 1, 2019 3:33 PM UTC
Answered

How to have multiple radio button values show in text field?

Hello,

I have a form with 4 groups of radio buttons ("Style" in the script below is one of the radio group names). I have created a text field at the end of the form where I would like the selection value from each radio group to display. I am able to get it to work for displaying one group value with the following, but need help with having it work for multiple group values?

event.value = this.getField("Style").value;

Appreciate any help.

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
May 2, 2019 9:17 PM UTC

You can replace all instances of "Off" from the final string, like this:

event.value = (this.getField("Style").value + " " + this.getField("Style2").value + " " + this.getField("Style3").value+ " " + this.getField("Style4").value).replace(/\s?Off\s?/g, "");

6 replies

Inspiring
May 1, 2019 10:17 PM UTC

When combining field values into a string, you should get the field values using the valueAsString property instead of the value property. It might not make any difference in this particular case, but it's a good habit to get into.

Translate
jillt1319Author
Participant
May 2, 2019 9:02 PM UTC

Thank you George. This also worked for me. Also looking for a way to remove the "Off" when no item is selected?

Translate
try67
Community Expert
Community Expert
May 1, 2019 4:10 PM UTC

Use something like this:

event.value = this.getField("Style").value + " " + this.getField("Style2").value + " " + this.getField("Style3").value+ " " + this.getField("Style4").value;

Note, though, that when no item is selected in the group the value is "Off".

Translate
jillt1319Author
Participant
May 2, 2019 8:52 PM UTC

Thank you much. That worked. Is there a way to remove the "Off" when no item is selected?

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 2, 2019 9:17 PM UTC

You can replace all instances of "Off" from the final string, like this:

event.value = (this.getField("Style").value + " " + this.getField("Style2").value + " " + this.getField("Style3").value+ " " + this.getField("Style4").value).replace(/\s?Off\s?/g, "");

Translate