spaceman12
spaceman12

Reputation: 1109

Detect textarea natural line breaks

I have a textarea element and on top of it, I also have a div block that superimposed exactly over the textarea (eg:-facebook comment box).Everything is going cool and fine not until this line-breaks comes into the scene. So I'm trying to detect every single line breaks( natural word-wrap) in the text area and insert a <br/> tags into the div block whenever it encounters.

Actually, looping over the characters in the textarea could have solve the issue but this would overkill the process particularly when the value of the textarea happens to be very long.

The "wrap-hard" attribute of the html5 is exactly what I need it but that requires one to submit the form.

Can someone suggest an ideal way to detect natural line breaks in the textarea? Many thanks!!!

Upvotes: 0

Views: 2486

Answers (2)

Lemex
Lemex

Reputation: 3794

Hopefuly these links will help you,

JavaScript: How to add line breaks to an HTML textarea?

http://www.sitepoint.com/forums/showthread.php?430599-lt-textarea-gt-new-line

just test for return character

Upvotes: 0

Related Questions