Tuesday, August 11, 2009

Writing content at the cursor location in text area

This was the problem and it ate all my day. Mozilla is a good boy and gives an attibute which can help, but IE.. aaah! what ever, the below is the code to do the same.

     var objTextArea = dc('contentId');
       document.selection.createRange().text = link.innerHTML;
       objTextArea.caretPos = document.selection.createRange().duplicate();

actually i got this from this site: http://forums.aspfree.com/html-javascript-and-css-help-7/tip-adding-text-in-caret-position-of-textarea-39329.html; infact he gives a working html code also.

No comments:

Post a Comment