Insert text in textarea at cursor position

C

cyber0ne

I have a textarea for users to post stuff on a website, but right now
it's just straight text and they have to add their own HTML tags for
formatting. This usually isn't a problem except for carriage returns.
Not being a Javascript guru by any means, I was looking up how to
detect the keypress event, check to see if it's a carriage return
(keycode 13, right?) and insert an HTML line break into the textarea.
It all looks good except for one thing, I can only append the HTML to
the end of the textarea. What if the user is going back and re-editing
text? Any carriage returns in the middle of the textarea would result
in an HTML line break at the end of the textarea.

So, is there a way to insert text at the cursor position when a
specific keyevent is detected? Does anyone have any example scripts
that do this? Ideally I'd like it to be as cross-platform as possible,
since I have about a 65:30:5::IE:Firefox:Other ratio of browsers that
hit the site.


Regards,
David P. Donahue
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top