# Connecting different script tags

**URL:** https://discourse.nodered.org/t/connecting-different-script-tags/43455
**Category:** Developing Nodes
**Created:** [31 March 2021 10:45 UTC](https://discourse.nodered.org/t/connecting-different-script-tags/43455 "2021-03-31T10:45:28Z")
**Posts on this page:** 7
**Page:** 2

<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: [1 April 2021 06:56 UTC](https://discourse.nodered.org/t/connecting-different-script-tags/43455/21 "2021-04-01T06:56:34Z")

</div>

> [@ivexy24](#):
>
> Any Idea why it doesnt fill my dropdown now?

Without seeing your code or knowing what you've tried to debug it - no, I don't.

---

<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: [1 April 2021 06:58 UTC](https://discourse.nodered.org/t/connecting-different-script-tags/43455/22 "2021-04-01T06:58:53Z")

</div>

Assuming you haven't changed the code you shared previously, then I can see you build up the `options` array in the response handler for the fetch, but you never do the work to update those options in the select box.

Your code does have the for loop at the start that loops over `options` - but at that point in time, the fetch hasn't happened yet, so `options` will be empty.

---

<div class="post-metadata">

### Author: ![ivexy24](https://avatars.discourse-cdn.com/v4/letter/i/df705f/32.png) [@ivexy24](https://discourse.nodered.org/u/ivexy24)
#### Post date: [1 April 2021 07:04 UTC](https://discourse.nodered.org/t/connecting-different-script-tags/43455/23 "2021-04-01T07:04:09Z")

</div>

```auto
    fetchUrl();
      for (let i = 0; i < options.length; i++) {
        let value = options[i].v;
        let text = options[i].t;
        $("#node-input-options").append(
          $("<option></option>").attr("value", value).text(text)
        );
      }
      $("#node-input-options").val(this.options);
      $("#node-input-server").val(this.server);
    },

    label: function () {
      let options = this.options;
      let optionText = "";

      for (let i = 0; i < options.length; i++) {
        if (options[i].v === this.options) {
          optionText = options[i].t;
          break;
        }
      }
      return this.name || "Custom Get";
    },

```

I have this code after the fetch request. I guess the problem is somewhere in there.

---

<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: [1 April 2021 07:07 UTC](https://discourse.nodered.org/t/connecting-different-script-tags/43455/24 "2021-04-01T07:07:51Z")

</div>

The call to `fetchUrl()` will return _before_ the request has completed - so when that for loop runs, `options` will still be empty.

You need to do the for loop inside the callback of the fetch request.

---

<div class="post-metadata">

### Author: ![ivexy24](https://avatars.discourse-cdn.com/v4/letter/i/df705f/32.png) [@ivexy24](https://discourse.nodered.org/u/ivexy24)
#### Post date: [1 April 2021 07:20 UTC](https://discourse.nodered.org/t/connecting-different-script-tags/43455/25 "2021-04-01T07:20:06Z")

</div>

```auto

        fetch(url)
          .then((res) => res.json())
          .then((data) => {
            opt = data;
            //console.log(opt);

            console.log(options);
            opt.forEach(myFunction);

            function myFunction(item) {
              // console.log(item);
              options.push({ v: item.address, t: item.name });
              console.log(options);
            }
          });
        for (let i = 0; i < options.length; i++) {
          let value = options[i].v;
          let text = options[i].t;
          $("#node-input-options").append(
            $("<option></option>").attr("value", value).text(text)
          );
        }
      };

      fetchUrl();

      $("#node-input-options").val(this.options);
      $("#node-input-server").val(this.server);
    },

    label: function () {
      let options = this.options;
      let optionText = "";

      for (let i = 0; i < options.length; i++) {
        if (options[i].v === this.options) {
          optionText = options[i].t;
          break;
        }
      }
      return this.name || "Custom Get";
    },
  });

```

Something like this? Its inside the fetch function but it still doesnt display anything.Probably i did somehting wrong .Ill figure it out.

---

<div class="post-metadata">

### Author: ![ivexy24](https://avatars.discourse-cdn.com/v4/letter/i/df705f/32.png) [@ivexy24](https://discourse.nodered.org/u/ivexy24)
#### Post date: [1 April 2021 07:26 UTC](https://discourse.nodered.org/t/connecting-different-script-tags/43455/26 "2021-04-01T07:26:29Z")

</div>

Nevermind. I made it work. Thanks for the help .

---

<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: [15 April 2021 07:26 UTC](https://discourse.nodered.org/t/connecting-different-script-tags/43455/27 "2021-04-15T07:26:57Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/connecting-different-script-tags/43455.md?page=1)
