I have a <textarea>
in a form, in which notes of the added information are written, the point is that if the user does not manually give it, enterhe does not make a line break and the information is completely straight, that goes to a table and that table by accommodate that text, unsettles the table, so there is a way to do it with js, jquery, I have searched but I have not achieved anything, if you could help me, I would appreciate it.
Left theHTML
<div class="form-group row ml-1 justify-content-center">
<label for="nota" class="col-form-label">Nota:</label>
<div class='col-sm-5 mr-3'>
<textarea name="nota" id="nota" class="form-control" cols="4" rows="3" maxlength="20"></textarea>
</div>
</div>
I would recommend you more to do the line break when pressing a special key such as the period key because using an amount n of characters could break words and this would affect the user's reading.
Using the event
keyup()
and propertieskey
andkeyCode
you can solve your problem:You can have a variable that counts the entered characters, once it reaches a certain limit that automatically applies a line break, you can do it in the following way.
In this example a line break is inserted for every 5 characters entered:
But I do not consider it to be the best option, if what you enter in it
<textarea>
are words and sentences, you could do it in this other way:In this example when you enter more than 10 characters the line break will be applied, but only when a space is entered, that way you will not have words cut off like in the previous example.
You can check it by typing text and copying it into a notepad, you will see the line breaks are introduced.
I hope it helps you, greetings.