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

JavaScript Code for Conditional Radio Buttons & List Box

New Here ,
Aug 20, 2020 Aug 20, 2020

Copy link to clipboard

Copied

I'm currently creating a form where many of the questions are conditional and I have never worked with JavaScript before.

For example, Q9 requires the user filling out the form to select radio buttons in Group "Q9" as "Yes" or "No". Based on their selection, a text box, another Yes/No set of radio buttons, or a list box will become required and change from "readonly=true" to "readonly=false". 

 

Another example, I'd like help with is for list box conditions. For example, Q9 has a list box appear after the Yes/No radio button has been selected, but the listbox has a second condition, the list box is multiple choice and if "Other" is chosen, a text box will become required and change from "readonly=true" to "readonly=false" as well to explain what "Other" is. 

 

Any help would be GREATLY appreciated!

TOPICS
Acrobat SDK and JavaScript

Views

248

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 ,
Aug 20, 2020 Aug 20, 2020

Copy link to clipboard

Copied

LATEST

You need to create a pair of radio buttons with the same name and a different export value for each.

 

In my example code below,  I am using "select" as the radio buttons fieldname.

 

One radio button will have "Choice1" as the export value and the other one "Choice2".

 

Use this code as a mouse-up action javascript for the radio button with export value "Choice1":

 

this.getField("myListBox").display = display.visible;

 

 

And do the same for the other radio button with export value of "Choice2  using this other line:

 

 

this.getField("myListBox").display = display.hidden;

 

 

Then add the following line of code to your list box as a mouse-up javascript action:

 

 

if (event.target.value =="Other") {

this.getField("myTextField").display = display.visible
} else {
 this.getField(myTextField").display = display.hidden;

} 

 

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