On my site (bible-help.com) I want to allow users to comment. When they click the ‘bold’ button, I want <b> and </b> to appear around the selected text (similar to this forum). Here is the code I have that works for Chrome, Firefox, and Safari. I can’t tell if it works on IE cause I use a mac.
[CODE]function formatText(el, tag)
{
if (el.setSelectionRange)
{
el.value = el.value.substring(0,el.selectionStart) + “<” + tag + “>” + el.value.substring(el.selectionStart,el.selectionEnd) + “</” + tag + “>” + el.value.substring(el.selectionEnd,el.value.length)
}
}
Does this work in IE?
If it doesn’t I saw this code somewhere:
[CODE]
function formatText(tag)
{
var selectedText = document.selection.createRange().text;
var newText = “<” + tag + “>” + selectedText + “</” + tag + “>”;
document.selection.createRange().text = newText;
}
Will that work in IE?
Currently on my site I have the two combined, but I don’t know if it works:
If you can’t tell by reading this, feel free to create an account on the website to try it. It’s like a forum and after signing in, click on +Add New Question.
Thanks for your help!