Skip to main content
Participant
May 2, 2022
Question

Dependent drop down list - I have seen many questions and answers but i can not get the code to work

  • May 2, 2022
  • 1 reply
  • 804 views

I am trying, like many others have on here, to get a dropdown list to appear dependent on another dropdown.  I have tried reading the forum and taking the code to use in my form but I can not get it to work properly.  I ma obviously out of my depth.  Can anyone please be of some assitance?  My initial dropdown box has 25 options, based upon their selection it should open up a specific set of responses in another dropdown.  

 

The first box's name is Potential Hazards, the dependent dropdown is Control Measures.  When the Potential Hazards has a selection of say Pinch Points, the Control Measure box should have a drop down box with a selection for PPE, Manpower, Proper Clearance, etc.  With some guidance I can extrapolate the remaining code.

 

A second thing that I would like to have is when a selection is made, dependent on the choice, a generic text comment can be put into another box.  Using the Potential Hazards example, if I selecet Pinch Points, I would like a generic comment installed into another box stating "Ensure all PPE and safety precautions are taken".  

 

Any and all help is greatly appreciated.  

 

 

Jason

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
May 2, 2022

 Lets say that text field is called "Info" as 'Validation' script of  "Potential Hazards" use this:

var f = this.getField("Control Measures");
var txt = this.getField("Info");
switch(event.value){
case "Pinch Points":
f.setItems(["PPE", "Manpower", "Proper Clearance"]);
txt.value = "Ensure all PPE and safety precautions are taken";
break;

default:
f.clearItems();
txt.value = "";}

 

In "Potential Hazards" dropdown field in options tab check "Commit selected value immediately".

 

Participant
May 3, 2022

Outstanding, that works great.  I can now modify the dependent drop down as needed.  One last question, hopefully;  In my potential hazards dropdown I have a selection of 20 or so options which should each bring up their pwn drop down in the control measures box.  How do I add a second option to the hazards drop down?  

 

var f = this.getField("Control Measures");
var txt = this.getField("Info");
switch(event.value){
case "Pinch Points":
f.setItems(["-Select your control measure-","PPE", "Manpower", "Proper Clearance"]);
txt.value = "Ensure all PPE and safety precautions are taken";
break;

default:
f.clearItems();
txt.value = "";}

 

In other words, how do I tranistion, or add the next selection after "pinch points"?  We can use "Arc Flash" as an example with control measure of  "wear glasses".  I can probably figure the rest out from there.  

 

Fingers crossed. 

 

Thanks again, 

Jason

Nesa Nurani
Community Expert
Community Expert
May 3, 2022

Add line between 'break' and 'default' like this:

var f = this.getField("Control Measures");
var txt = this.getField("Info");
switch(event.value){
case "Pinch Points":
f.setItems(["-Select your control measure-","PPE", "Manpower", "Proper Clearance"]);
txt.value = "Ensure all PPE and safety precautions are taken";
break;

case "Arc Flash":

f.setItems(["-Select your control measure-","PPE", "Manpower", "Proper Clearance"]);
txt.value = "Ensure all PPE and safety precautions are taken";

break;

default:
f.clearItems();
txt.value = "";}

Of course change 'f.setItems' and 'txt.value' to whatever you want.