Sending the message to the next node

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 :slight_smile:
btw i used Dashboard Template.


<!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>

Could you provide your flow? (see How to share code or flow json)

Are you using the template or ui-template node?

i'm using ui-template node

[{"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}]

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

So in your template put declaration

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

Then when using it to send


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