# Sending the message to the next node

**URL:** <https://discourse.nodered.org/t/sending-the-message-to-the-next-node/17245>\
**Category:** General\
**Created:** [28 October 2019 18:16 UTC](https://discourse.nodered.org/t/sending-the-message-to-the-next-node/17245 "2019-10-28T18:16:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bader](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@Bader](https://discourse.nodered.org/u/Bader)\
**Post date:** [28 October 2019 18:16 UTC](https://discourse.nodered.org/t/sending-the-message-to-the-next-node/17245/1 "2019-10-28T18:16:26Z")

</div>

Hello guys, i wanna send the x to the next node(mqtt out) and i tried node.send(x) and msg.payload to send the x but it did'nt work, anyone can help me with that 🙂  
btw i used Dashboard Template.

```auto

<!DOCTYPE html>
<html>
<head>
<style>
/* This stylesheet sets the width of all images to 100%: */
img {
  width: 100%;
  height: 55%;
}
</style>
</head>
<body>
<img id="lightz" src="https://www.edrawsoft.com/templates/images/living-room-design-plan.png" alt="Pic" width="649"
height="422" usemap="#Test">

<map name="Test">
  <area shape="circle" coords="264,28,7" alt="light1" onclick="myFunction()">
  <area shape="circle" coords="263,168,7" alt="light2" href="https://www.youtube.com/">
</map>

<script>
var x=0;
function myFunction() {
  if(x===0){
  alert("Light is ON!");
  document.getElementById('lightz').src='https://i.ibb.co/WcwbWKf/2.png';
   x =1 ;}
  else
  {
  alert("Light is OFF!");
  document.getElementById('lightz').src='https://www.edrawsoft.com/templates/images/living-room-design-plan.png';
   x = 0;
  }
  msg.x = x;
  node.send(x);
  return msg;

  }
</script>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 October 2019 21:41 UTC](https://discourse.nodered.org/t/sending-the-message-to-the-next-node/17245/2 "2019-10-28T21:41:42Z")

</div>

Could you provide your flow? (see [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506))

Are you using the template or ui-template node?

---

<div class="post-metadata">

**Author:** ![Bader](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@Bader](https://discourse.nodered.org/u/Bader)\
**Post date:** [29 October 2019 06:00 UTC](https://discourse.nodered.org/t/sending-the-message-to-the-next-node/17245/3 "2019-10-29T06:00:36Z")

</div>

i'm using ui-template node

```auto
[{"id":"2f8d264e.315b5a","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"168ffcdf.49fec3","type":"ui_template","z":"2f8d264e.315b5a","group":"7df6c9e4.2fe848","name":"","order":1,"width":"0","height":"0","format":"\n<!DOCTYPE html>\n<html>\n<head>\n<style>\n/* This stylesheet sets the width of all images to 100%: */\nimg {\n width: 100%;\n height: 55%;\n}\n</style>\n</head>\n<body>\n<img id=\"lightz\" src=\"https://www.edrawsoft.com/templates/images/living-room-design-plan.png\" alt=\"Pic\" width=\"649\"\nheight=\"422\" usemap=\"#Test\">\n\n<map name=\"Test\">\n <area shape=\"circle\" coords=\"264,28,7\" alt=\"light1\" onclick=\"myFunction()\">\n <area shape=\"circle\" coords=\"263,168,7\" alt=\"light2\" href=\"https://www.youtube.com/\">\n</map>\n\n<script>\nvar x=0;\n\nfunction myFunction() {\n if(x===0){\n alert(\"Light is ON!\");\n document.getElementById('lightz').src='https://i.ibb.co/WcwbWKf/2.png';\n x =1 ;}\n else\n {\n alert(\"Light is OFF!\");\n document.getElementById('lightz').src='https://www.edrawsoft.com/templates/images/living-room-design-plan.png';\n x = 0;\n }\n\n }\n</script>\n</body>\n</html>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":500,"y":280,"wires":[["95330f58.ce5f8","ffae42f8.2632c"]],"outputLabels":["x"]},{"id":"95330f58.ce5f8","type":"debug","z":"2f8d264e.315b5a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":240,"wires":[]},{"id":"ffae42f8.2632c","type":"mqtt out","z":"2f8d264e.315b5a","name":"","topic":"","qos":"","retain":"","broker":"961e00a7.0b8a6","x":710,"y":300,"wires":[]},{"id":"7df6c9e4.2fe848","type":"ui_group","z":"","name":"Lights","tab":"bac79aeb.7c1288","order":1,"disp":true,"width":"6","collapse":false},{"id":"961e00a7.0b8a6","type":"mqtt-broker","z":"","name":"","broker":"","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"bac79aeb.7c1288","type":"ui_tab","z":"","name":"Living room","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

```

---

<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:** [29 October 2019 06:53 UTC](https://discourse.nodered.org/t/sending-the-message-to-the-next-node/17245/4 "2019-10-29T06:53:08Z")

</div>

You have to use the scope to send and/or receive

So in your template put declaration

```auto
//Make scope available in functions
var theScope = scope;

```

Then when using it to send

```auto

theScope.send({payload:'whatever'});

```
