Skip to main content
Participant
September 18, 2024
Answered

Multiple radio button selection to habilitate a text field

  • September 18, 2024
  • 2 replies
  • 567 views

Can someone please assist in script that would make a text field called PLAN mandatory to fill up with the following conditions?: 

If 5 or more of the radio buttons in the RED column are selected, the text PLAN has to be mandatory

Also

If 7 or more of the BLUE column are selected, the text field PLAN has to be mandatory

All sets of radio button are called in groups as per the first column, the RED column has a value of 1 and the BLUE an option of 5.

I truly appreciate your help. And Thanks!!

 

This topic has been closed for replies.
Correct answer Nesa Nurani

I assume numbers on the left are radio button names (1.1, 1,2...etc), use this script in "PLAN" field as custom calculation script under 'Calculate' tab:

 

var fields = ["1.1","1.2","1.3","1.4","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","5.1","6.1","6.2","6.3","6.4","6.5","7.1","8.1"];
var red = 0;
var blue = 0;
for(var i=0; i<fields.length; i++){
 var f = this.getField(fields[i]).valueAsString;
 if(f === "1")red++;
 if(f === "5")blue++;}

event.target.required = (red>=5 || blue>=7) ? true : false;

 

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 18, 2024

I assume numbers on the left are radio button names (1.1, 1,2...etc), use this script in "PLAN" field as custom calculation script under 'Calculate' tab:

 

var fields = ["1.1","1.2","1.3","1.4","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","5.1","6.1","6.2","6.3","6.4","6.5","7.1","8.1"];
var red = 0;
var blue = 0;
for(var i=0; i<fields.length; i++){
 var f = this.getField(fields[i]).valueAsString;
 if(f === "1")red++;
 if(f === "5")blue++;}

event.target.required = (red>=5 || blue>=7) ? true : false;

 

Participant
September 18, 2024

Thank you very much!!

Participant
September 18, 2024

I forgot to clarify that all 20 questions have to be selected in one of the columns with the radio buttons.