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

How to write validation script for one dropdown that is conditional based on another dd's selection

Explorer ,
Jun 23, 2025 Jun 23, 2025

There are two different dropdowns (named "dd1" and "dd2") with the same 13 selections ("a" through "m")

When "a" or "b" is selected, a hide field should to appear.

Example script for both dd1 and dd2:

if((event.value =="a") || (event.value =="b")) {
this.getField("Hide").display = display.visible;
} else {
this.getField("Hide").display = display.hidden;
}

 

This script works for both dropdown's, however, if the selection for "dd1" was NOT

 "a" or "b", the hide field needs to stay hidden even if  "a" or "b" is selected from "dd2".

 

Is there a way to add this condition to the validation script for "dd2" (i.e., reference "dd1" and it's selections)?

 

Any help would be appreciated!

TOPICS
How to , JavaScript , PDF forms
186
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 24, 2025 Jun 24, 2025

Something like this:

var dd1Value = this.getField("dd1").value;
var dd2Value = event.value;

if ((dd1Value == "a" || dd1Value == "b") && (dd2Value == "a" || dd2Value == "b")) {
 this.getField("Hide").display = display.visible;} 
else {
 this.getField("Hide").display = display.hidden;}

View solution in original post

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 ,
Jun 23, 2025 Jun 23, 2025

Check also the value of the other dropdown. 

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 ,
Jun 23, 2025 Jun 23, 2025

If implemented this way, the second script becomes redundant. It cannot influence the visibility of the "Hide" field unless dd1 is set to "a" or "b"—but in that case, the field is already made visible by the primary script tied to dd1. Therefore, the second script serves no functional purpose in this 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
Explorer ,
Jun 24, 2025 Jun 24, 2025

The example script shown above is to have the text field "Hide" visible when the either "a" or "b" is selected from the dropdown and hidden when any of the other options (e.g., "c") is selected. This portion works as is should. The problem I have is that if "a" or "b" is NOT selected in both dd1 and dd2, the "Hide" field needs to be hidden, even if "a" or "b" is selected from dd2. Is there a way to write in the validation code for dd2, that if "dd1" event.value does not equal "a" or "b" then the text field "Hide" should be hidden? I am not sure how to refer to a separate dropdown field (i.e., refer to "dd1" in the validation script for "dd2". I hope this explains what I am trying to do more clearly.

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 ,
Jun 24, 2025 Jun 24, 2025

Something like this:

var dd1Value = this.getField("dd1").value;
var dd2Value = event.value;

if ((dd1Value == "a" || dd1Value == "b") && (dd2Value == "a" || dd2Value == "b")) {
 this.getField("Hide").display = display.visible;} 
else {
 this.getField("Hide").display = display.hidden;}
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
Explorer ,
Jun 24, 2025 Jun 24, 2025
LATEST

That worked! Thank you so much for your time and expertise.

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