Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Multiple Dependent Dropdowns

New Here ,
Dec 13, 2024 Dec 13, 2024

Hello! I am fairly new to the whole javascript thing. I have edited a form for work to make it easier for people to make selections. I created a dependent drop down that based on the job that you pick, it gives you locations to select that you can go to. The field has asked for an additional dependency that would change only one job's locations, depending on if you have 3 years of experience or if you had less than 3 years (which already has a drop down).

Is there a way to link this together?

 

meaning:

Job A can go to x, y, or z.

Job B can go to x, y, or z if they have 1 to 3 years or a, b or c if the dropdown is set to 3+ years

TOPICS
Acrobat SDK and JavaScript , Windows
441
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Dec 13, 2024 Dec 13, 2024

Use two condition within condition for Job B, something like this:

var location = this.getField("Location");
var exp = Number(this.getField("Experience").valueAsString);
if(event.value == "Job A")
 location.setItems(["x","y","z"]);
else if(event.value == "Job B"){
 if(exp >= 1 && exp <=3)
  location.setItems(["x","y","z"]);
 else if(exp > 3)
  location.setItems(["a","b","c"]);}

This is just an example script to demonstrate the functionality.

How you implement it will depend on how you select the

...
Translate
Community Expert , Dec 15, 2024 Dec 15, 2024

Use like this, but instead in 'Validate' tab use it in 'Calculate' tab as custom calculation script of the field where you select Job:

 

if (event.source && (event.source.name=="Experience" || event.source.name==event.target.name)) {
var location = this.getField("Location");
var exp = Number(this.getField("Experience").valueAsString);
if(event.value == "Job A")
 location.setItems(["x","y","z"]);
else if(event.value == "Job B"){
 if(exp >= 1 && exp <=3)
  location.setItems(["x","y","z"]);
 else i
...
Translate
Community Expert ,
Dec 13, 2024 Dec 13, 2024

Use two condition within condition for Job B, something like this:

var location = this.getField("Location");
var exp = Number(this.getField("Experience").valueAsString);
if(event.value == "Job A")
 location.setItems(["x","y","z"]);
else if(event.value == "Job B"){
 if(exp >= 1 && exp <=3)
  location.setItems(["x","y","z"]);
 else if(exp > 3)
  location.setItems(["a","b","c"]);}

This is just an example script to demonstrate the functionality.

How you implement it will depend on how you select the "Experience" years. If "Experience" is a separate dropdown (like in my example), and you use a validate script to populate another dropdown, you need to ensure that the user selects the experience first. Otherwise, the logic might not execute as intended.

Alternatively, you can use a calculation script, where you'll need to reference the dropdown field using event.source to dynamically update the dependent dropdown. This approach avoids relying on selection order but requires a slightly different setup.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 15, 2024 Dec 15, 2024

This gave me a great option! The experience use to be a drop down but I switched it to a text box. Is there a way that I can do it without having to input the experience first? Usually when we send the form, we select the job for them from a drop down and they complete the rest. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2024 Dec 15, 2024

Use like this, but instead in 'Validate' tab use it in 'Calculate' tab as custom calculation script of the field where you select Job:

 

if (event.source && (event.source.name=="Experience" || event.source.name==event.target.name)) {
var location = this.getField("Location");
var exp = Number(this.getField("Experience").valueAsString);
if(event.value == "Job A")
 location.setItems(["x","y","z"]);
else if(event.value == "Job B"){
 if(exp >= 1 && exp <=3)
  location.setItems(["x","y","z"]);
 else if(exp > 3)
  location.setItems(["a","b","c"]);}}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 15, 2024 Dec 15, 2024
LATEST

This worked perfectly! Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines