Send message using keypress event

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.

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


html input i am using to access the script.

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

Kindly help me to send output in keypress event.

Try something along the lines of...

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

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