- From: Biju <bijumaillist@gmail.com>
- Date: Mon, 10 May 2010 03:59:00 -0400
Current way in firefox is to
1. OrigStart = textarea.selectionStart
2. textarea.value = textarea.value.substr(0, OrigStart)
+ new_text_to_replace
+ textarea.value.substr(textarea.selectionEnd);
3. Now u loose original selection, so
4. textarea.setSelectionRange(OrigStart, OrigStart+new_text_to_replace.length)
5. remember .scrollTop and reapply if needed
Now if we are only changing few selected characters in TEXTAREA with
big text content,
we are unnecessarily replacing entire content, which is inefficient.
On IE even though wierd you can do it simply by
document.selection.createRange().text = new_text_to_replace;
BTW, you need to make sure the selection is currently on the
textarea/input form control.
IE is also very fast when doing that, when firefox hangs few second
using the other way
Received on Monday, 10 May 2010 00:59:00 UTC