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

How to I use a radio button to populate a dropdown selection?

New Here ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

I am very new to Javascripting.  I need to have a dropdown value be automatically selected when a radio button is selected.  Is this possible?  I haven't seen much on these forums about this and I don't know where to start.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.4K

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 ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

Yes, it is.  Any field value is set by, ready for it, setting the value. So all you need to do is set the dropdown value when the radio button changes.

Do this with a calculation script on the dropdown.

Method 1 (radio button export is different from dropdown items)

var cRadValue = this.getField("RadioButton").value;

if(cRadValue == "Choice1")

   event.value = "Something1";

else if(cRadValue == "Choice2")

   event.value = "Something2";

else

  event.value = "Unselected Optin";

But if you want to get clever, name the radio button export values the same as the Dropdown Export values.

Then this script will work.

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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
New Here ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

I appreciate your quick response!

I think that I figured out another way to do this. In Actions on the radio button I put this script in and it seems to have satified my requirements:

if(this.getField("Group1").value == "Patient Travel")  

this.getField("3-Letter Dropdown").value = "SGH"; 

}

The other radio buttons in the group I set it to reset that dropdown since I only needed one radio button to populate a drop down.

Not sure if this was the best way to go about it. 

I tried your way out, and I kept getting a syntax error.  Definitely is user error.  As I said I am not at all proficient in Javascript.  Learning on the fly and these forums help out a ton!

Thank you again for taking your time to help.

-Stephen

Votes

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 ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

LATEST

So, if you got a syntax error, it means there is a syntax error and you should fix it. It's got nothing to do with the methodology.

There are two issues with using a mouse action to set a value. Neither of these is a show stopper as long as the radio button value is always set by the user physically clicking on the button.  This method fails when the radio value is either set by a script or by importing data.

1. This is an efficiency and robustness issue: You have to maintain scripts in several places, whereas the calculation script is one thing that handles all cases.

2. This is the real issue:  a Mouse action  is by definition a UI event, not a value event. When handling values, it is best to use value related events. In the case of a radio button there is a direct connection between the UI event and the Value. But not between the value the and UI event, i.e. no MouseUp event is triggered if a script is used to change the radio button.

It is unfortunate that Adobe choose not to include a change event into the properties dialog for the radio button and check box. This event actually exists and you can set it with a script, but you can't enter it from the Acrobat UI.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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