Forum Moderators: open

Message Too Old, No Replies

Finding and inserting text using caretPos

How can I do this in non-IE browsers?

         

GaryK

11:58 pm on Aug 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The below code is used to store the system caret in a textarea and then use it to insert text at that position. Unfortunately it only works in IE. I always know what browser my users are using so is there code that will work in non-IE browsers? Thanks.


function InsertTextAtSystemCaret(paramTextAreaObject, paramTextToInsert) {
if (paramTextAreaObject.createTextRange && paramTextAreaObject.caretPos) {
var caretPos = paramTextAreaObject.caretPos;
caretPos.text =
caretPos.text.charAt(caretPos.text.length - 1) == ' '?
text + ' ' : paramTextToInsert;
} else {
paramTextAreaObject.value = paramTextAreaObject.value + paramTextToInsert; // non-IE browsers
}
return true;
}


function StoreSystemCaret(paramTextAreaObject) {
if (paramTextAreaObject.createTextRange) { paramTextAreaObject.caretPos = document.selection.createRange().duplicate(); }
}

GaryK

4:18 pm on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does the lack of response mean this can't be done? Or that my thread got lost in all the traffic? I'd sure appreciate some help with this problem. Many thanks.