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

How to select a specific dropdown item using JavaScript

Community Beginner ,
Apr 21, 2024 Apr 21, 2024

I've created a dropdown menu named "Product" with 3 items in this order : "item1", "item2" and "item3".

Wondering if someone can help me with the javascript code that will allow "item2" to be selected.

Thanks

TOPICS
JavaScript , PDF forms
1.1K
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 ,
Apr 22, 2024 Apr 22, 2024

JavaScript is case sensitive, it's not "item2" it's "Item 2" including space, and it's not "Type2" it's "Type 2", you need to be very specific, try this:

if(event.value == "Item 2")
this.getField("Type").value = "Type 2";

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 ,
Apr 21, 2024 Apr 21, 2024

Here you go:

this.getField("Product").value = "item2";

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 ,
Apr 22, 2024 Apr 22, 2024

Thank you for reply, unfortunaltely it didn't work. 

FYI, I've created 2 dropdown menu: "Type" and "Product"

- "Type" has 3 items : "Type1" , "Type2" and "Type3"

- "Product" has 3 items : "item1", "item2" and "item3"

I need a javascript code to set the dropdown "Type" value to "Type2" when the "item2" is selceted in "Product".

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 ,
Apr 22, 2024 Apr 22, 2024

You should explain like that in the first post 🙂

Use this as 'Validate' script of "Product" field:

if(event.value == "item2")
this.getField("Type").value = "Type2";

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 ,
Apr 22, 2024 Apr 22, 2024

Still not working 😞  please check the file in the attchement

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 ,
Apr 22, 2024 Apr 22, 2024

JavaScript is case sensitive, it's not "item2" it's "Item 2" including space, and it's not "Type2" it's "Type 2", you need to be very specific, try this:

if(event.value == "Item 2")
this.getField("Type").value = "Type 2";

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 ,
Apr 22, 2024 Apr 22, 2024
LATEST

it works! thank you for your assitance

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