# Send message using keypress event

**URL:** <https://discourse.nodered.org/t/send-message-using-keypress-event/29175>\
**Category:** Dashboard\
**Created:** [29 June 2020 15:05 UTC](https://discourse.nodered.org/t/send-message-using-keypress-event/29175 "2020-06-29T15:05:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhanasekar](https://avatars.discourse-cdn.com/v4/letter/d/c4cdca/32.png) [@dhanasekar](https://discourse.nodered.org/u/dhanasekar)\
**Post date:** [29 June 2020 15:05 UTC](https://discourse.nodered.org/t/send-message-using-keypress-event/29175/1 "2020-06-29T15:05:44Z")

</div>

I am using ui\_template. I would like to send payload at the time of clicking "enter" key. I am using the below script. but not working. But alert function working fine in keypress event.

```auto
<script>
        
            $(function ($scope) 
            {
                $('.decimal').keypress(function decimal(e) 
                {
                    if (event.key === 'Enter') {
                        $scope.send({payload: "test"});  
                       // alert($(this).val());
                        /*(function($scope) {
                        $scope.send({payload: "test"});   
                                })(scope);
                        
                        alert($(this).val());*/
                        
                    }
                    var character = String.fromCharCode(e.keyCode)
                    var newValue = this.value + character;
                    if (isNaN(newValue) || parseFloat(newValue) * 1000 % 1 > 0) {
                        e.preventDefault();
                        return false;
                    }
                })(e);

            })(scope);
        </script>

```

html input i am using to access the script.

```auto
<input type="text" id="salary" class="decimal" />

```

Kindly help me to send output in keypress event.

---

<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:** [29 June 2020 19:40 UTC](https://discourse.nodered.org/t/send-message-using-keypress-event/29175/2 "2020-06-29T19:40:51Z")

</div>

Try something along the lines of...

```auto
$('.decimal').on('keypress',function(ev) {
    var keycode = (ev.keyCode ? ev.keyCode : ev.which);
    if(keycode == 13) {
        //Enter pressed
    }
});

```

---

<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:** [29 July 2020 19:40 UTC](https://discourse.nodered.org/t/send-message-using-keypress-event/29175/3 "2020-07-29T19:40:53Z")

</div>

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