1

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

The width of the textarea is dynamically done via CSS (e.g., #myTextArea { width: 80%; }) so I can't do anything like counting the characters in each line.

I don't need a non-JS solution since the content of the textarea is only ever seen by JavaScript anyways.

Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
MiffTheFox
  • 21,302
  • 14
  • 69
  • 94
  • This will be difficult; but, just out of curiosity, why do you want this? As you'll probably know textareas wordwrap nicely by default. – Marcel Korpel Jun 25 '10 at 03:16
  • For what exactly you need to do that? Depending on what you want the style `word-wrap:break-word;` can perhaps solve your problem. – BrunoLM Jun 25 '10 at 03:16
  • @Marcel - Yes, but in a way that's invisible to the script. – MiffTheFox Jun 25 '10 at 15:08

1 Answers1

0

This is a really nasty problem to try and solve. I'd be going down either 1 of 2 pahts. 1 just use the text area as is or 2 using a nice jQuery editor which makes the text look nice.

griegs
  • 22,624
  • 33
  • 128
  • 205