# Sending msg.payload inside template function

**URL:** <https://discourse.nodered.org/t/sending-msg-payload-inside-template-function/4669>\
**Category:** General\
**Created:** [8 November 2018 08:58 UTC](https://discourse.nodered.org/t/sending-msg-payload-inside-template-function/4669 "2018-11-08T08:58:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BastianG](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@BastianG](https://discourse.nodered.org/u/BastianG)\
**Post date:** [8 November 2018 08:58 UTC](https://discourse.nodered.org/t/sending-msg-payload-inside-template-function/4669/1 "2018-11-08T08:58:02Z")

</div>

Hi All.

I'm using a dashboard template to make some buttons. Each button fires an simple function inside the template.  
I have problems sending a msg.payload from the function.

I can't use the predefined ng-click. Here is what i have so far:

```
 <button
 ontouchstart="touchFuncttion(0)"
 ontouchend="touchFunction(1)">
 </button>
 
 <script>
 var Q = 1;
 function touchFunction(Q) {
 if (Q===0){
 send something to msg.payload;
 }
 else if (Q===1) {
 send something else to msg.payload;
 }
 }
 </script>

```

Any one who knows how to do this? 🙂

Best Regards Bastian

---

<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:** [8 November 2018 09:00 UTC](https://discourse.nodered.org/t/sending-msg-payload-inside-template-function/4669/2 "2018-11-08T09:00:03Z")

</div>

Have you read the help provided with the ui\_template node in the Info sidebar? It has a section on how to send messages.

---

<div class="post-metadata">

**Author:** ![BastianG](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@BastianG](https://discourse.nodered.org/u/BastianG)\
**Post date:** [8 November 2018 10:37 UTC](https://discourse.nodered.org/t/sending-msg-payload-inside-template-function/4669/3 "2018-11-08T10:37:04Z")

</div>

Hi There.

I have read it again and again. The problem is that it uses ng-click to fire this.scope.action. I can't use the predefined ng-directives because it has poor touchsupport. So basically I need to send an msg.payload inside a function in the template.

Best Regards

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [9 November 2018 19:56 UTC](https://discourse.nodered.org/t/sending-msg-payload-inside-template-function/4669/4 "2018-11-09T19:56:30Z")

</div>

Maybe this could be helpful

> [@Extract html input field value to payload](https://discourse.nodered.org/t/extract-html-input-field-value-to-payload/4568):
>
> Hey all, I've created an input field in the template node and I just want to extract it to use in my flows. Here's the basic input field (without the brackets): input type="text" name="joel" And then I'd like to take the users input and do something with it. How can I access the value in the html input field and use it in my node-red flow logic?
