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

Set the value of a radio button with Javascript

Mentor ,
Mar 13, 2019 Mar 13, 2019

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
4.2K
Translate
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";

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

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

Translate
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

Thank you.

Translate
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

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?

Translate
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

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

var mySelection = event.value;

Translate
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

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

Translate
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

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.

Translate
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

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

Translate
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

Important to remember: JavaScript is case-sensitive.

Translate
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

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

Translate
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

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

Translate
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

Sure they are:

export.jpg

Translate
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

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

Translate
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

Ah.

Translate
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

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

Translate
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
LATEST

Got it, thank you both!

Translate
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