0

I tried several codes but still, it's not working.

$(".chatboxtextarea").on('keypress', function(e){

  if(e.keyCode == 13 && !e.shiftKey){

    $('#file_name #fileLoader').show();
    console.log('loader div triggered!');

    if($.trim($(this).val()).length > 0){

      if ((entr === false) && (submt === false)) {
        sendMessageClient();
        entr = true;
      }

    }else{
         $(this).focus();
    }

  }

}); 
Amrinder Singh
  • 5,300
  • 12
  • 46
  • 88
isha
  • 11
  • 2
  • 1
    It's not really clear what you are trying to achieve. Please clarify what you are trying to do. – JiFus Jun 30 '17 at 06:59
  • shift+enter is not working .after click on it form will submit. I tried StackOverflow codes. but still, it's not working. – isha Jun 30 '17 at 07:08
  • `if(e.keyCode == 13 && !e.shiftKey)` means "if key is enter and shift not pressed" – xmike Jun 30 '17 at 09:33

1 Answers1

0

If you want to prevent the creating of a new line from happening you can use the following code:

$("textarea").keydown(function(e){

    // Enter was pressed without shift key
    if (e.keyCode == 13 && !e.shiftKey)
    {
        // prevent default behavior
        e.preventDefault();
    }
});

(Copy paste from here)

This will prevent the default behaviour from happening when pressing enter (but not pressing shift at the same time) inside a textarea.

Also, this jsFiddle is mentioned in the answer.

JiFus
  • 959
  • 7
  • 19
  • thanks . enter is working properly. but after the click ( shift+enter ) it's not creating a new line. – isha Jun 30 '17 at 07:21