Automatic new line in textarea

Using jQuery, how can I create a text field that automatically adds a new line when inserting text when the cursor is near the end.

The width of the text box is dynamically done through CSS (for example, #myTextArea { width: 80%; }), so I can do nothing but count the characters in each line.

I do not need a solution other than JS, since the contents of the text field are ever viewed by JavaScript.

+1
source share
2 answers

You can get the estimated pixel width in the text area and debug textarea. You can see the horizontal width of the font (or mode, or whatever you like). You can guess about kerning. See what I get? (hint: calculate string length in characters)

You mentioned counting characters, so I assume you already know how to do this. :-)

+1
source

This is a very nasty problem to try to solve. I would go down either to 1 of 2 buttermilk. 1 just use the text area as is or 2 using a good jQuery editor that makes the text enjoyable.

0
source

All Articles