Skip to main content
Participating Frequently
December 12, 2024
Answered

Need help autopopulating a dropdown based on the selections from other 2 dropdowns

  • December 12, 2024
  • 1 reply
  • 186 views

Hello,

I am new to javascript. I followed a tutorial to be able to autopopulate a dropdown based on another, but I don't know how to make it work based on the selections of two dropdowns.


I have 7 options in the first column (discipline), and 5 levels in the second column (level). Depending on what is selected in those two, I need to auto populate different options in the third row (power).

¿Could someone help me with that?

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

You can use something like this as custom calculation script of 3rd dropdown, change choices with actual values:

if (event.source && (event.source.name=="row1.discipline" || event.source.name=="row1.level")) {
var d1 = this.getField("row1.discipline").valueAsString;
var d2 = this.getField("row1.level").valueAsString;

if(d1 == "Choice1" && d2 == "Choice2")
event.target.setItems(["Choice1", "Choice2", "Choice3"]);
else if(d1 == "Choice2" && d2 == "Choice2")
event.target.setItems(["Choice4", "Choice5", "Choice6"]);
else
event.target.clearItems();}

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
December 12, 2024

You can use something like this as custom calculation script of 3rd dropdown, change choices with actual values:

if (event.source && (event.source.name=="row1.discipline" || event.source.name=="row1.level")) {
var d1 = this.getField("row1.discipline").valueAsString;
var d2 = this.getField("row1.level").valueAsString;

if(d1 == "Choice1" && d2 == "Choice2")
event.target.setItems(["Choice1", "Choice2", "Choice3"]);
else if(d1 == "Choice2" && d2 == "Choice2")
event.target.setItems(["Choice4", "Choice5", "Choice6"]);
else
event.target.clearItems();}