# Accesing dropdown in js file

**URL:** <https://discourse.nodered.org/t/accesing-dropdown-in-js-file/45221>\
**Category:** Developing Nodes\
**Created:** [5 May 2021 13:20 UTC](https://discourse.nodered.org/t/accesing-dropdown-in-js-file/45221 "2021-05-05T13:20:00Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [6 May 2021 10:51 UTC](https://discourse.nodered.org/t/accesing-dropdown-in-js-file/45221/21 "2021-05-06T10:51:15Z")

</div>

if i have 1 option selected it consoles logs right id. If i have multiple then it shows always the same value for each selected

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 May 2021 11:00 UTC](https://discourse.nodered.org/t/accesing-dropdown-in-js-file/45221/22 "2021-05-06T11:00:24Z")

</div>

Without seeing the code you are trying, I have no idea.

---

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [6 May 2021 11:38 UTC](https://discourse.nodered.org/t/accesing-dropdown-in-js-file/45221/23 "2021-05-06T11:38:54Z")

</div>

```auto
    let selectValue = node.selectValue;
      let e = $("#node-input-options")[0];
      let sel = e.options[i][e.selectedIndex].id;
      for (let i = 0; i < options.length; i++) {
        node.selectValue = sel[i];
        console.log(node.selectValue);
      }

```

This is in oneditsave function. Without the loop if i select only 1 option everything works fine

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 May 2021 11:59 UTC](https://discourse.nodered.org/t/accesing-dropdown-in-js-file/45221/24 "2021-05-06T11:59:15Z")

</div>

You don't appear to have read the stackoverflow post I shared.

To get the list of selected values you can do:

```auto
node.selectedValue = $("#node-input-options").val()

```

At which point, `node.selectValue ` will be an array of the selected values.

I'm not 100% sure what that will do if you only have one element selected - you'd have to test to see if it always returns an array or not.

Now, if you're changing `node.selectValue` to be an array, rather than a single value, you'll have to change the `oneditprepare` code to handle it being an array as well.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 May 2021 12:00 UTC](https://discourse.nodered.org/t/accesing-dropdown-in-js-file/45221/25 "2021-05-20T12:00:07Z")

</div>

Closed on 20 May 2021 12:00 UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/accesing-dropdown-in-js-file/45221.md?page=1)
