Skip to main content
Known Participant
April 26, 2021
Answered

Radio button determines which text fields in table are required

  • April 26, 2021
  • 2 replies
  • 2824 views

I have a radio button named group6. There are 3 options to choose from directorder, POR, buildandreplace.

Depending on which option you choose determines which columns of the table need to be filled out. If you select directorder or POR, then if you fill out an item code and you must enter the quantity in that row of the table. If you select billandreplace and all the columns in the order form are required. Below is an image of the order form.

 

The 1st row the item code name is itemcode1.0. So the action for that field is set to mouse up and run JavaScript. Here is the script that I wrote:

 

if (event.value.length>0 && getField("group6").value == "directorder") {
this.getField("qty1.0").required = true;

}

 

I would repeat this code for each item code row. But it's not working. What am I doing wrong? I have it set so that the form validates prior to being submitted. It alerts the user of any required fields that are not filled in. If I enter an item code none of the required fields are mentioned in the alert.

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

Put this code as "calculation script" in one of the fields:

for( var i=0; i<=11; i++){
if(this.getField("itemcode1."+i).valueAsString != "" && (this.getField("group6").valueAsString == "directorder" || this.getField("group6").valueAsString == "POR")){
this.getField("qty1."+i).required = true;
this.getField("serialnumber1."+i).required = false;
this.getField("servicefee1 replace1."+i).required = false;}
else if(this.getField("itemcode1."+i).valueAsString != "" && this.getField("group6").valueAsString == "billandreplace"){
this.getField("qty1."+i).required = true;
this.getField("serialnumber1."+i).required = true;
this.getField("servicefee1 replace1."+i).required = true;}
else {
this.getField("qty1."+i).required = false;
this.getField("serialnumber1."+i).required = false;
this.getField("servicefee1 replace1."+i).required = false;}}

 

2 replies

Nesa Nurani
Nesa NuraniCorrect answer
Inspiring
April 26, 2021

Put this code as "calculation script" in one of the fields:

for( var i=0; i<=11; i++){
if(this.getField("itemcode1."+i).valueAsString != "" && (this.getField("group6").valueAsString == "directorder" || this.getField("group6").valueAsString == "POR")){
this.getField("qty1."+i).required = true;
this.getField("serialnumber1."+i).required = false;
this.getField("servicefee1 replace1."+i).required = false;}
else if(this.getField("itemcode1."+i).valueAsString != "" && this.getField("group6").valueAsString == "billandreplace"){
this.getField("qty1."+i).required = true;
this.getField("serialnumber1."+i).required = true;
this.getField("servicefee1 replace1."+i).required = true;}
else {
this.getField("qty1."+i).required = false;
this.getField("serialnumber1."+i).required = false;
this.getField("servicefee1 replace1."+i).required = false;}}

 

Known Participant
April 26, 2021

When I entered that script as a custom calculation script, it automatically defaults back to the "value is not calculated" option. It won't except that code. Any thoughts on why?

Nesa Nurani
Inspiring
April 26, 2021

Can you share your file?

Inspiring
April 26, 2021

Please share your file or show screenshot of field names.

Known Participant
April 26, 2021

Inspiring
April 26, 2021

Ok, just quick question. If item code is filled and rb directorder or POR is selected only qty column is required, and if billandreplace is selected all fields are required?