# Node Button Event

**URL:** <https://discourse.nodered.org/t/node-button-event/40313>\
**Category:** Developing Nodes\
**Created:** [3 February 2021 14:40 UTC](https://discourse.nodered.org/t/node-button-event/40313 "2021-02-03T14:40:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeevan900929](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeevan900929/32/36306_2.png) [@jeevan900929](https://discourse.nodered.org/u/jeevan900929)\
**Post date:** [3 February 2021 14:40 UTC](https://discourse.nodered.org/t/node-button-event/40313/1 "2021-02-03T14:40:23Z")

</div>

I have a node with a button that has an onClick event

```auto
<script type="text/javascript">
    RED.nodes.registerType('connect', {
        category: 'ringbeller',
        color: '#8d6b94',
        defaults: {
            name: { value: "" },
            settings: { value: "", type: "configuration" }
        },
        inputs: 1,
        outputs: 1,
        icon: "file.png",
        label: function () {
            return this.name || "Connect to the Modem";
        },
        button: {
            enabled: function () {
                return !this.changed
            },
            onclick: function () { 
                console.log('CLICKED')
            }
        }
    });
</script>

```

How do I trigger this node to run, or cause it's input callback to fire, when this button is clicked?

  
Thanks

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 February 2021 23:21 UTC](https://discourse.nodered.org/t/node-button-event/40313/2 "2021-02-03T23:21:09Z")

</div>

Look at the inject node code on node-red repo. It typically calls an endpoint that you create in the js file.

---

<div class="post-metadata">

**Author:** ![jeevan900929](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeevan900929/32/36306_2.png) [@jeevan900929](https://discourse.nodered.org/u/jeevan900929)\
**Post date:** [4 February 2021 00:33 UTC](https://discourse.nodered.org/t/node-button-event/40313/3 "2021-02-04T00:33:16Z")

</div>

I searched the repo for inject, but only found tests for inject, not the node itself. Could you please share the link to the file?

Thank you

---

<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:** [4 February 2021 00:43 UTC](https://discourse.nodered.org/t/node-button-event/40313/4 "2021-02-04T00:43:39Z")

</div>

Hi @jeevan900929

Here is where the node creates the http admin endpoint: [node-red/20-inject.js at fad8dcd304728014551da41186d25db9f7320abd · node-red/node-red · GitHub](https://github.com/node-red/node-red/blob/fad8dcd304728014551da41186d25db9f7320abd/packages/node_modules/%40node-red/nodes/core/common/20-inject.js#L155)

And here is where it gets called: [node-red/20-inject.html at fad8dcd304728014551da41186d25db9f7320abd · node-red/node-red · GitHub](https://github.com/node-red/node-red/blob/fad8dcd304728014551da41186d25db9f7320abd/packages/node_modules/%40node-red/nodes/core/common/20-inject.html#L620)

---

<div class="post-metadata">

**Author:** ![jeevan900929](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeevan900929/32/36306_2.png) [@jeevan900929](https://discourse.nodered.org/u/jeevan900929)\
**Post date:** [4 February 2021 01:10 UTC](https://discourse.nodered.org/t/node-button-event/40313/5 "2021-02-04T01:10:04Z")

</div>

I have a `connectToModem` function in the node:

```auto
  function ConnectNode (config) {
    ...
    const connectToModem = function () {
      ... 
    }
  }

```

How would I refer to this function from the onClick callback function:

```auto
button: {
            enabled: function () {
                return !this.changed
            },
            onclick: function () { 
                   **Needs to be called from here**
                      ConnectNode.connectToModem() ?
            }
        }

```

Thanks

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [4 February 2021 05:20 UTC](https://discourse.nodered.org/t/node-button-event/40313/6 "2021-02-04T05:20:55Z")

</div>

You call it from the http endpoint in the js file. When you look at the first link above you see the inject does something similar. There a function node.receive() gets called from the endpoint upon request.

---

<div class="post-metadata">

**Author:** ![jeevan900929](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeevan900929/32/36306_2.png) [@jeevan900929](https://discourse.nodered.org/u/jeevan900929)\
**Post date:** [4 February 2021 10:19 UTC](https://discourse.nodered.org/t/node-button-event/40313/7 "2021-02-04T10:19:24Z")

</div>

Great, thanks!

---

<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:** [18 February 2021 10:19 UTC](https://discourse.nodered.org/t/node-button-event/40313/8 "2021-02-18T10:19:25Z")

</div>

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