Javascript, textareas, selected text and IE
Posted: Fri Jun 08, 2007 10:11 am
I have a textarea that I want to grab the selected text from in all browsers for use in a bbCode insertion tool.
The code I have:
Works fine in Firefox, but doubles over (uses all text as selected region) in Internet Explorer.
Any suggestions on fixing the problem for IE?
The code I have:
Code: Select all
function addCode(code,codeclose) {
var Text = document.form.content.value;
var selectedText = Text.substring(document.form.content.selectionStart, document.form.content.selectionEnd);
var beforeSelected = Text.substring(0,document.form.content.selectionStart);
var afterSelected = Text.substring(document.form.content.selectionEnd,Text.length);
document.form.content.value = beforeSelected+code+selectedText+codeclose+afterSelected;
}Code: Select all
javascript:addCode('[b]','[/b]')Any suggestions on fixing the problem for IE?