I have no experience with using JS to work inside a textarea. I know it's doable as I've seen it.
Links anyone?
Try this for starters:
http://www.w3schools.com/jsref/dom_obj_textarea.asp