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

Community Beginner ,
May 01, 2019

Copy link to clipboard

Copied

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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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, "");

TOPICS
Acrobat SDK and JavaScript

Views

92

Likes

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

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

Community Beginner ,
May 01, 2019

Copy link to clipboard

Copied

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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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, "");

TOPICS
Acrobat SDK and JavaScript

Views

93

Likes

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
May 01, 2019 0
Most Valuable Participant ,
May 01, 2019

Copy link to clipboard

Copied

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".

Likes

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
Reply
Loading...
May 01, 2019 2
Community Beginner ,
May 02, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
May 02, 2019 0
Most Valuable Participant ,
May 02, 2019

Copy link to clipboard

Copied

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, "");

Likes

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
Reply
Loading...
May 02, 2019 2
Community Beginner ,
May 02, 2019

Copy link to clipboard

Copied

Awesome. This worked, much appreciated.

Likes

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
Reply
Loading...
May 02, 2019 0
Adobe Community Professional ,
May 01, 2019

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
May 01, 2019 2
Community Beginner ,
May 02, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
May 02, 2019 0