WebAsh
11-11-2005, 12:04 AM
Well... this is a last resort, kinda hoped i would have found it with some Google searches... but no... What i need is to be able to replace a portion of text within a textarea that is selected. I have got it working for Firefox (havent tried Opera yet) but when I went over to IE it didn't work at all. I need it for a rich text editor sort of interface like vBulletin and so on have.
Hope you can understand what i want... I'll post the javascript i have come up with so far that works in Firefox.
function bbcodeinsert (txtarea, code, attribute) {
txt = txtarea.value;
if ( document.all ) {
//IE CODE HERE!
} else if ( document.getElementById ) {
startselect = txtarea.selectionStart;
endselect = txtarea.selectionEnd;
/*alert(startselect);
alert(endselect);*/
if ( startselect != endselect) {
var selectedtext = txt.substring(startselect,endselect);
if ( !attribute ) {
extra = "";
} else {
extra = "=" & attribute;
}
bbcode = "[" + code + extra + "]" + selectedtext + "[/" + code + "]";
result = (txt.substring(0, startselect-1)) + bbcode + (txt.substring(endselect+1));
/*alert(txt);
alert(txtarea);
alert(code);
alert(attribute);
alert(selectedtext);
alert(extra);
alert(bbcode);
alert(result);*/
txtarea.value = result;
} else {
alert('Please select the text you want the action to be performed on');
}
}
}
Hope you can understand what i want... I'll post the javascript i have come up with so far that works in Firefox.
function bbcodeinsert (txtarea, code, attribute) {
txt = txtarea.value;
if ( document.all ) {
//IE CODE HERE!
} else if ( document.getElementById ) {
startselect = txtarea.selectionStart;
endselect = txtarea.selectionEnd;
/*alert(startselect);
alert(endselect);*/
if ( startselect != endselect) {
var selectedtext = txt.substring(startselect,endselect);
if ( !attribute ) {
extra = "";
} else {
extra = "=" & attribute;
}
bbcode = "[" + code + extra + "]" + selectedtext + "[/" + code + "]";
result = (txt.substring(0, startselect-1)) + bbcode + (txt.substring(endselect+1));
/*alert(txt);
alert(txtarea);
alert(code);
alert(attribute);
alert(selectedtext);
alert(extra);
alert(bbcode);
alert(result);*/
txtarea.value = result;
} else {
alert('Please select the text you want the action to be performed on');
}
}
}