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

Hide or Show Text Fields based on result of 7 radio buttons Yes/No

New Here ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

I have 7 radio buttons groups.   PD.Q1 to PD.Q7 

Each one is Yes or No

I have two text fields.  PDW.Warning1 and PDW.Warning2.

Each one is hidden by default.

 

My objective is to show these warning text boxes based on the result of the radio buttons.  The intent is that if any of the radio button groups are selected "Yes", then the warning will appear, regardless of its 1, or all 7.  If all of the radio buttons are selected "No", then the warnings will remain hidden.

I wrote this in the calculations of one of the text boxes, and it works, but it has issues.

It shows the hidden warnings, but its a "sequencial" process, meaning when a user checks the first yes, then the second no, it shows, then hides the text boxes.

I need the warning to remain after a "Yes", and only hide when all radio buttons are "No".

 

if(!event.source || (event.source.name = "PD"))

{

var nHide=(event.source.value=="Yes")?display.visible:display.hidden;

this.getField("PDW").display=nHide;

}

Thanks in Advance!

TOPICS
Acrobat SDK and JavaScript

Views

653

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 2 Correct answers

Community Expert , May 05, 2020 May 05, 2020

You must test all 7 radio buttons.

Votes

Translate

Translate
New Here , May 05, 2020 May 05, 2020

You've almost got the right idea, but there are several issue with your code.

 First, this line.

      event.source.name = "PD"

is an assignment, not a comparison, And the name of the fieild are only prefixed with "PD" the name is longer so this comparison won't work. The firs t The first line needs to be this

 

if(!event.source || /^PD\./.test(event.source.name))

 

Next, all the checkboxes need to be tested. You've named them perfected for this. So here's the complete code. 

if(!event.source || /^PD\./
...

Votes

Translate

Translate
New Here ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

I also tried this from a 1 and 0 return perspective.  But its showing the warning text when the NO/0 value is checked.

var nResult = this.getField("PD").value;

if(nResult=1){

this.getField("PDW").display=display.visible

}

else if (nResult=0){

this.getField("PDW").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
Community Expert ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

You must test all 7 radio buttons.

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 05, 2020 May 05, 2020

Copy link to clipboard

Copied

You've almost got the right idea, but there are several issue with your code.

 First, this line.

      event.source.name = "PD"

is an assignment, not a comparison, And the name of the fieild are only prefixed with "PD" the name is longer so this comparison won't work. The firs t The first line needs to be this

 

if(!event.source || /^PD\./.test(event.source.name))

 

Next, all the checkboxes need to be tested. You've named them perfected for this. So here's the complete code. 

if(!event.source || /^PD\./.test(event.source.name)){
   var aFldList = this.getField("PD").getArray();
   var nHide= aFldList.some(function(a){return a.value == "Yes";})?display.visible:display.hidden;

   this.getField("PDW").display=nHide;
}

 

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 05, 2020 May 05, 2020

Copy link to clipboard

Copied

LATEST

Beautiful, thank you both so much for the much needed boost.  All I got to say is  I can't wait for my kids Daycare to open back up.......

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