I'm doing it for texarea. A function should be called when the user press Enter, but nothing should be done when Shift + Enter be pressed.
I try to simulate here a feature that many IM communicators have: sending a message on Enter but also adding multiple lines using Shift + Enter.
To detect shift+enter and generate a new line in text area with JavaScript, we can check for shift and enter key presses in the event object. textArea. onKeyPress = (e) => { if (e. keyCode === 13 && e.
To check if an “enter” key is pressed inside a textbox, just bind the keypress() to the textbox. $('#textbox'). keypress(function(event){ var keycode = (event.
To check whether user pressed ENTER key on webpage or on any input element, you can bind keypress or keydown event to that element or document object itself. Then in bind() function check the keycode of pressed key whether it's value is 13 is not.
To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.
Test for the enter keycode (13) and if shift key was pressed.
...onkeyup = function(e) { if (e.keyCode == 13) { // if (e.shiftKey === true) if (e.shiftKey) // thruthy { // new line } else { // run your function } return false; } }
Edit: Accept all truthy values of e.shiftKey
element.onkeydown = function(o) { o = o || event; if (o.shiftKey && o.keyCode == 13) { /* shift + enter pressed */ } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With