Forum Moderators: open
Now, it still inserts at the cursor fine, but is no longer recognising that there is any text selected, and is instead inserting "undefined" between the tags, over the top of any selected text(if any is selected)
The code is as follows:
function insertAtCursor(bb_tex, bb_val) {
if (window.document.selection) {
bb_tex.focus();
sel = window.document.selection.createRange();
sel.text = bb_val;
} else if (bb_tex.selectionStart || bb_tex.selectionStart == '0') {
var startPos = bb_tex.selectionStart;
var endPos = bb_tex.selectionEnd;
bb_tex.value = bb_tex.value.substring(0, startPos)
+ bb_val
+ bb_tex.value.substring(endPos, bb_tex.value.length);
} else {
bb_tex.value += bb_val;
}
}
var st = window.document.selection.createRange().text; and then the function would be used like:
insertAtCursor(window.document.newspost.content, '[u]' + st + '[/u]'); It's probably something really simple, but I'm too much of a noob at JS to work it out :S
Anyway, any help anyone could offer would be much appreciated :)