PDA

View Full Version : IE textarea createRange problem



kirkh
10 Nov 2010, 5:24 AM
Hello.

Here is IE problem.

In aplication I'm working on has a textarea and a combo. Selected item from combo must been pasted to the caret position in textarea. When combo selected, textarea loses focus. That why to get textRange i use blur event of textarea


listeners: { 'blur': function(field, newValue, oldValue)
{
sel = document.selection.createRange();
}
}


All works fine when i select at least 1 character. Selected character replaced by the value selected in my combo.
But if it is no one character selected nothing is happend((.

Code I use to insert to textarea


var sel;

function insertTextOnPosition(textArea, text)
{
var value = textArea.getValue();
if (Ext.isIE)
{
sel.text = text;

} else {
var startPos = textArea.el.dom.selectionStart;
var endPos = textArea.el.dom.selectionEnd;
value = value.substring(0, startPos) + text + value.substring(endPos, value.length);
textArea.setValue(value);
}
}


What is wrong?

Thanks.