The text area tag defines a multi-line text input control. The size of a text area can be specified by the cols and rows attributes. By default, whenever we press “enter” or “shift+enter” it creates a new line in the text area. So, to only detect “shift+enter” and generate a new line from it we need to block “enter” from generating a new line and to redirect it to do something else like submitting.
Example 1: Check out the following Example for “enter” and “shift+enter” mechanism. So, here in the below code both “enter” and “shift+enter” do the same. So, all that has to be done is to either block the “enter” mechanism or redirecting it to do something else.
Example 2: In the below code, we created a function(submitForm()) to submit the form which just contains a line, because placing this document.geek.submit() under event.preventDefault(), document.geek.submit() will overrides the event.preventDefault() and never blocks the “enter” from creating a line.
HTML in submit.html:
- How to detect Alt/Option + another key in textarea ?
- How to add line breaks to an HTML textarea?
- New self vs. new static in PHP
- How to put string in array, split by new line in PHP ?
- How to add a new line in the alert box ?
- How to avoid a new line with tag?
- How to disable resizable property of textarea using CSS?
- HTML | DOM Textarea Object
- AngularJS | textarea Directive
- How to make sure clients have enough words in textarea by using angularjs in order to disable/enable a button?
- How to make textarea 100% without overflow when padding is present ?
- How to get the value of a textarea in jQuery ?
- How to insert text into the textarea at the current cursor position?
- How to stop submit button from expanding along with textarea?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.