Hi all,
I would like to insert into a text area. at the cursor position (or replace selected text), a text .
I'm trying to use the following script, but I can not make it work.
(see .. http://stackoverflow.com/questions/5889127/insert-value-into-textarea-where-cursor-was)
thanks in advance
Regards
saverio
=======================================
My texarea item is P200_AFORMULA
========================================
function insertAt (myField, myValue, startSel, endSel) {
if (startSel || startSel == '0') {
var startPos = startSel;
var endPos = endSel;
myField.val(myField.val().substring(0, startPos)+ myValue+ myField.val().substring(endPos, myField.val().length));
}
else {
myField.val() += myValue;
}
}
// calling the function
var targetBox = $("textarea#P200_AFORMULA"),startSel,endSel;
targetBox.bind('focusout', function() {
//insertAtCursor(this, 'how do you do');
startSel = this.selectionStart;
endSel = this.selectionEnd;
});
var mytext = 'INSETED TEXT';
insertAt(targetBox, mytext , startSel, endSel);
}