Hello.
I've been using this function to insert text at the selection in a text field.
It works fine in IE and firefox, but not in opera.Code:function insertAtCursor(myField, myValue) { //IE support if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); myField.focus(); myField.selectionStart = myField.selectionEnd = myField.value.substring(0, startPos).length + myValue.length; } else { myField.value += myValue; } }
In opera it creates a double.
Lets say I have this text: Cake is tasty.
I then select the text and use the function to insert this: Cake is tasty.
Firefox and IE will replace the selection, as I want to to, but opera just inserts it after the text, so it ends up like this: Cake is tasty.Cake is tasty.
Anyone knows why opera is acting up/behaving differently?
Any help is appreciated.


Reply With Quote
Bookmarks