Detect “Shift+Enter” And Generate New Line In JS

Hello, Hope you are doing well .!

In this article, We will learn the most common requirements in web applications that are based on JS. For example: How to detect shift + enter and generate a new line. So let’s start



<!DOCTYPE html>
  <script src=""></script>
  <h1 style="color:gray;">Detect “Shift+Enter”</h1>
  <h4>Press "enter" or "shift+enter" in the textarea, both does the same.</h4>
  <textarea rows="8" cols="50" onkeypress="detectShiftEnterFunc(event)"></textarea>
   	<p id="msg" style="color:red"></p>
  function detectShiftEnterFunc(event) {
    // 13 is the keycode for "enter"
    if (event.keyCode == 13 && event.shiftKey) {
      $('#msg').html("Triggered enter+shift");
    if (event.keyCode == 13 && !event.shiftKey) {
      $('#msg').html("Triggered enter");



Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories