Skip to main content
Participating Frequently
April 21, 2024
Answered

How to select a specific dropdown item using JavaScript

  • April 21, 2024
  • 1 reply
  • 1462 views

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

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

Still not working 😞  please check the file in the attchement


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";

1 reply

Nesa Nurani
Community Expert
Community Expert
April 22, 2024

Here you go:

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

RsTm16Author
Participating Frequently
April 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".

Nesa Nurani
Community Expert
Community Expert
April 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";