• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Set the value of a radio button with Javascript

Mentor ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Quick syntax question: If I have a radio button group called "Answer" with the options "Yes", "No", and "Maybe", how can I use Javascript to select one of those options?

TOPICS
Acrobat SDK and JavaScript

Views

1.8K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 13, 2019 Mar 13, 2019

this.getField("Answer").value = "Maybe";

Likes

Translate

Translate
Community Expert ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

this.getField("Answer").value = "Maybe";

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
community guidelines
Mentor ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Thank you.

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
community guidelines
Mentor ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

On my test form, I have a dropdown menu (named "Selection") where the user makes their selection, and then on another page, that same selection is displayed in a radio button group (named "Result") with that option checked. The export values in the dropdown and the radio button group are the same. Here's what I did:

On the dropdown menu field, I added a Javascript to be executed on MouseUp:

var mySelection = this.getField("Selection").value;

this.getField("Result").value = mySelection;

I also checked the "Commit selected value immediately" option.

It's not working properly; the selections in the radio group are always one selection behind the selections in the dropdown list, exactly as they would be if I had not selected the "Commit selected value immediately" option. What am I doing wrong?

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
community guidelines
Community Expert ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Move it to the Validation event and change the first line to:

var mySelection = event.value;

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
community guidelines
Mentor ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Hmm... it's not working for me. Would you mind looking at my PDF?

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
community guidelines
Community Expert ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Sure. You can share it via Dropbox, Google Drive, Adobe Document Cloud, etc., or you can email it to me directly to try6767 at gmail.com.

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
community guidelines
Mentor ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

I tried sharing it with Dropbox, but I'm not sure if it worked. Here's a link from WeTransfer.

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
community guidelines
Community Expert ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Important to remember: JavaScript is case-sensitive.

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
community guidelines
Mentor ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Right... all my export values are in lower case. Do you see a typo somewhere?

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
community guidelines
Community Expert ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

The export values of the drop down are not lower case.

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
community guidelines
Mentor ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Sure they are:

export.jpg

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
community guidelines
Community Expert ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Right, but the "event.value" property returns the display value, though.

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
community guidelines
Mentor ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

Ah.

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
community guidelines
Community Expert ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

I would recommend getting rid of the export values and changing the values of the radio-buttons to match those in the drop-down.

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
community guidelines
Mentor ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

LATEST

Got it, thank you both!

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
community guidelines