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

How to populate a different dropdown list based on selection of a value in the first dropdown field?

Community Beginner ,
Jun 29, 2022 Jun 29, 2022

Hi there,

I am trying to make a selection from one drop-down list (Service) that populates different items in the second drop-down list (Units of measure).

I found another similar question in the community but when I use the code (I am not a coder) I keep getting the following error- syntaxError: unterminated string literal 4: at line 5.

 

Here is the code:

if(event.value == "Storage")
this.getField("Unit of measure 2.0.12.1").setItems(["Per Standard* Pallet","Per Non-Standard Pallet","Per Bin","Per Square Foot"]);
else if(event.value == "IN Handling")
this.getField("Unit of measure 2.0.12.1").setItems(["Per Pallet 'IN'","Per Carton 'IN'","]);
else this.getField("Unit of measure 2.0.12.1").clearItems();

if(event.value == "Item1")
this.getField("Dropdown2").setItems(["Item 1","Item 2","Item 3"]);
else if(event.value == "Item2")
this.getField("Dropdown2").setItems(["Item 4","Item 5","Item 6"]);
else this.getField("Dropdown2").clearItems();

  This is not the complete drop-down as I wanted to try it first. Also, I am guessing this would go in the first dropdown field? I would really appreciate some help! 

TOPICS
JavaScript , PDF forms
870
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 29, 2022 Jun 29, 2022

You have an extra quotation mark, remove red part:

this.getField("Unit of measure 2.0.12.1").setItems(["Per Pallet 'IN'","Per Carton 'IN'","]);

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 29, 2022 Jun 29, 2022

As the error message says, you have an unterminated string in your code, specifically in the last item in the array in this line:

this.getField("Unit of measure 2.0.12.1").setItems(["Per Pallet 'IN'","Per Carton 'IN'","]);

And yes, this code should be used as the custom validation script of the first drop-down.

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 Beginner ,
Jun 29, 2022 Jun 29, 2022

Thank you so much for offering your help.

I guess I am asking how to fix this? How do I terminate it? What is the code I need to make it work? I don't see any open square parenthesis. 

 

 

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 29, 2022 Jun 29, 2022

You have an extra quotation mark, remove red part:

this.getField("Unit of measure 2.0.12.1").setItems(["Per Pallet 'IN'","Per Carton 'IN'","]);

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 Beginner ,
Jun 29, 2022 Jun 29, 2022
LATEST

Thank you so much! I've been staring at this forever trying to figure out where I went wrong. I am so relieved.

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