# Send message from a html input button on template back to node red

**URL:** https://discourse.nodered.org/t/send-message-from-a-html-input-button-on-template-back-to-node-red/69831
**Category:** General
**Created:** [31 October 2022 12:06 UTC](https://discourse.nodered.org/t/send-message-from-a-html-input-button-on-template-back-to-node-red/69831 "2022-10-31T12:06:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Henrique](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Henrique](https://discourse.nodered.org/u/Henrique)
#### Post date: [31 October 2022 12:06 UTC](https://discourse.nodered.org/t/send-message-from-a-html-input-button-on-template-back-to-node-red/69831/1 "2022-10-31T12:06:43Z")

</div>

can i send a msg to the node red debug from a template node? i made a site with the http in - template - http out and i want that when i click a button (not a submit button, just a ) the node red debug receives some message like the value or anything.

i thought about change the msg.payload and return it on the debug but how do i do that? i already asked here how do i change a flow variable inside the template node but nothing yet

---

<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: [31 October 2022 13:04 UTC](https://discourse.nodered.org/t/send-message-from-a-html-input-button-on-template-back-to-node-red/69831/2 "2022-10-31T13:04:36Z")

</div>

> [@Henrique](#):
>
> can i send a msg to the node red debug from a template node

Read the built in help of the ui-template.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7b9ed45c1c69ee7b2f235c2be38867019a903ce9.png)

Search the forum: [Search results for 'send message from template' - Node-RED Forum](https://discourse.nodered.org/search?q=send%20message%20from%20template)  
e.g: [Ui-template: sending msg through a function - #4 by Steve-Mcl](https://discourse.nodered.org/t/ui-template-sending-msg-through-a-function/59686/4)

---

<div class="post-metadata">

### Author: ![Henrique](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Henrique](https://discourse.nodered.org/u/Henrique)
#### Post date: [31 October 2022 13:51 UTC](https://discourse.nodered.org/t/send-message-from-a-html-input-button-on-template-back-to-node-red/69831/3 "2022-10-31T13:51:23Z")

</div>

can i do it on regular template?

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [31 October 2022 13:54 UTC](https://discourse.nodered.org/t/send-message-from-a-html-input-button-on-template-back-to-node-red/69831/4 "2022-10-31T13:54:36Z")

</div>

Yes you can (I do this often, although I prefer websockets for interaction)

In template node, example

```auto
<button onclick="test()">to node-red</button>
<script>
function test(){
const send = fetch("http://your-node-red-ip:1880/yoururlendpoint?clicked=true")
}

</script>

```

attach a debug node to the http-in node, look for the payload when the button is clicked.

![SCR-20221031-kp7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad9cbbee793c72ef1bc16ae3c411c0c8cc3f8899.png)

---

<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: [31 October 2022 14:47 UTC](https://discourse.nodered.org/t/send-message-from-a-html-input-button-on-template-back-to-node-red/69831/5 "2022-10-31T14:47:57Z")

</div>

My appologies, I completely threw the part about using http-in nodes out of my brain and ploughed for the usual dashboard example.

As @bakman2 points out - you have to take care of posting data from the front-end to the back end & has provided a working example too.

My only advice would be use a parameterised endpoint e.g. `web1/api/v1/:fn` then you can post to URLs like `web1/api/v1/create` or `web1/api/v1/update` or `web1/api/v1/delete` and in your function test what is in `msg.req.params.fn` to route your messages as required by the intended `fn`.

---

<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: [14 November 2022 14:48 UTC](https://discourse.nodered.org/t/send-message-from-a-html-input-button-on-template-back-to-node-red/69831/6 "2022-11-14T14:48:15Z")

</div>

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