Translation of text when applied to ENTER



  • Hello. I have a text field, not even textarea, but just a input, no button, and it shouldn't be. I need you to do ajax function when you press ENTER in the text field.

    <input placeholder='Введите сообщение...' id='txtmess'>
    

    function gomess() { //Отправить сообщение
    var id = $("#idus").text();
    var txtmess = $("#txtmess").val();
    $.ajax({
    type: 'POST',
    url: '/obr/mess.php',
    data: 'idus='+ id +'&txt='+ txtmess,
    success: function(data) {
    alert(data);
    },
    error: function(xhr, str){
    alert(data);
    }
    });
    }

    Found this function. onkeydownI don't know how to use it. ♪ ♪
    Specify any functions or desirable violin for example.



  • Tie the function to the button, for example:

    document.onkeyup = function (e) {
            e = e || window.event;
            if (e.keyCode === 13) {
                alert("Вы нажали Enter!");
            }
            // Отменяем действие браузера
            return false;
        }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2