Skip to main content
Participant
May 5, 2020
해결됨

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

  • May 5, 2020
  • 3 답변들
  • 1074 조회

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!

이 주제는 답변이 닫혔습니다.
최고의 답변:

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;
}

 

3 답변

답변
May 5, 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\./.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;
}

 

chuckmcgavin작성자
Participant
May 5, 2020

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.......

Bernd Alheit
Community Expert
Community Expert
May 5, 2020

You must test all 7 radio buttons.

chuckmcgavin작성자
Participant
May 5, 2020

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

}