# Press button to send msg.payload

**URL:** <https://discourse.nodered.org/t/press-button-to-send-msg-payload/37653>\
**Category:** Dashboard\
**Created:** [17 December 2020 14:57 UTC](https://discourse.nodered.org/t/press-button-to-send-msg-payload/37653 "2020-12-17T14:57:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![diegotorpocop](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@diegotorpocop](https://discourse.nodered.org/u/diegotorpocop)\
**Post date:** [17 December 2020 14:57 UTC](https://discourse.nodered.org/t/press-button-to-send-msg-payload/37653/1 "2020-12-17T14:57:54Z")

</div>

Hello,

The dashboard I am creating will be used in a touchscreen, therefore I am placing buttons (numbers from 0-9) that will emulate a keypad. When I press a button it will send the number 1 to a text input.

The problem I am facing is that it only sends one message of value 1 or if I press the button 2 it erases the value of 1 and it only lets one value of 2. I want to be able to for example type an ID but the button will only send one message payload (something like concatenation of strings or summing numbers that will be later stored as a string).

````auto
[{"id":"42ccc6dc.3f6c58","type":"ui_text_input","z":"ee1b56d.0bd78a8","name":"","label":"Escriba su DNI","tooltip":"","group":"9012e58c.845058","order":1,"width":0,"height":0,"passthru":true,"mode":"number","delay":"0","topic":"","x":420,"y":120,"wires":[["9045aa50.887db8","c9d2789a.fa6378"]]},{"id":"d8c65fef.321f","type":"ui_button","z":"ee1b56d.0bd78a8","name":"key_1","group":"9012e58c.845058","order":2,"width":"1","height":"1","passthru":false,"label":"","tooltip":"","color":"","bgcolor":"","icon":"filter_1","payload":"1","payloadType":"num","topic":"","x":130,"y":100,"wires":[["42ccc6dc.3f6c58"]]},{"id":"c5e54acb.d9dfe8","type":"ui_button","z":"ee1b56d.0bd78a8","name":"key_1","group":"9012e58c.845058","order":2,"width":"1","height":"1","passthru":false,"label":"","tooltip":"","color":"","bgcolor":"","icon":"filter_2","payload":"2","payloadType":"num","topic":"","x":130,"y":140,"wires":[["42ccc6dc.3f6c58"]]},{"id":"c9d2789a.fa6378","type":"ui_button","z":"ee1b56d.0bd78a8","name":"","group":"9012e58c.845058","order":2,"width":0,"height":0,"passthru":false,"label":"Ok","tooltip":"","color":"White","bgcolor":"Green","icon":"done","payload":"msg.payload","payloadType":"str","topic":"","x":590,"y":140,"wires":[["971cac2d.5847c"]]},{"id":"9012e58c.845058","type":"ui_group","name":"DNI","tab":"45adf96f.3d0388","order":1,"disp":true,"width":"6","collapse":false},{"id":"45adf96f.3d0388","type":"ui_tab","name":"Bienvenido al modulo de triaje","icon":"dashboard","order":1,"disabled":false,"hidden":false}]```
````

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 December 2020 15:32 UTC](https://discourse.nodered.org/t/press-button-to-send-msg-payload/37653/2 "2020-12-17T15:32:46Z")

</div>

You would need to store the previous numbers and add the new number to the end of the stored value each time. example below

```auto
[{"id":"15dbd844.8d2828","type":"ui_button","z":"8d22ae29.7df6d","name":"key_1","group":"165e1e1a.e752fa","order":2,"width":"1","height":"1","passthru":false,"label":"","tooltip":"","color":"","bgcolor":"","icon":"filter_2","payload":"2","payloadType":"str","topic":"","x":70,"y":2740,"wires":[["29907992.f4458e"]]},{"id":"29907992.f4458e","type":"function","z":"8d22ae29.7df6d","name":"","func":"let value = context.get(\"keyvalue\") || \"\";\nif (msg.payload === \"reset\"){\n context.set(\"keyvalue\",\"\");\n msg.payload= \"\";\n return msg;\n}else if(msg.payload === \"send\"){\n// msg.payload = Number(value);\n msg.payload = value;\n\n return [null,msg];\n}else{\n msg.payload = value + msg.payload;\n context.set(\"keyvalue\",msg.payload);\n}\nreturn msg;","outputs":2,"noerr":0,"initialize":"","finalize":"","x":260,"y":2720,"wires":[["b8bf7ce9.9802e"],["249db316.6fff34"]]},{"id":"968fabdf.58b878","type":"ui_button","z":"8d22ae29.7df6d","name":"key_1","group":"165e1e1a.e752fa","order":2,"width":"1","height":"1","passthru":false,"label":"","tooltip":"","color":"","bgcolor":"","icon":"filter_1","payload":"1","payloadType":"str","topic":"","x":70,"y":2700,"wires":[["29907992.f4458e"]]},{"id":"aeeb1b36.6adf28","type":"ui_button","z":"8d22ae29.7df6d","name":"","group":"165e1e1a.e752fa","order":2,"width":0,"height":0,"passthru":false,"label":"reset","tooltip":"","color":"","bgcolor":"","icon":"done","payload":"reset","payloadType":"str","topic":"","x":70,"y":2780,"wires":[["29907992.f4458e"]]},{"id":"b8bf7ce9.9802e","type":"ui_text","z":"8d22ae29.7df6d","group":"165e1e1a.e752fa","order":9,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":410,"y":2700,"wires":[]},{"id":"249db316.6fff34","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":2760,"wires":[]},{"id":"eeecee34.8af5d","type":"ui_button","z":"8d22ae29.7df6d","name":"","group":"165e1e1a.e752fa","order":2,"width":0,"height":0,"passthru":false,"label":"send","tooltip":"","color":"","bgcolor":"","icon":"done","payload":"send","payloadType":"str","topic":"","x":70,"y":2820,"wires":[["29907992.f4458e"]]},{"id":"165e1e1a.e752fa","type":"ui_group","z":"","name":"Default","tab":"f9b58883.fa613","order":1,"disp":true,"width":"12","collapse":false},{"id":"f9b58883.fa613","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![diegotorpocop](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@diegotorpocop](https://discourse.nodered.org/u/diegotorpocop)\
**Post date:** [18 December 2020 16:21 UTC](https://discourse.nodered.org/t/press-button-to-send-msg-payload/37653/3 "2020-12-18T16:21:47Z")

</div>

Thank you!

---

<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:** [1 January 2021 16:21 UTC](https://discourse.nodered.org/t/press-button-to-send-msg-payload/37653/4 "2021-01-01T16:21:47Z")

</div>

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