Hello everyone, I’m trying to write a very crude BBCode insertion script on my site. I’m definitely not great with JavaScript I am currently having trouble getting a couple scripts I found on the internet to work together. By themselves, they seem okay, but I think I messed something up when I tried to put them together. Can someone please take a look at this script and tell me why nothing happens when I visit the page and test it? It currently does not work in any browser. Thank you for your time.
Javascript:
[CODE]function addtag(tag) {
if (TextAreaContent.createTextRange && TextAreaContent.caretPos) {
var caretPos = TextAreaContent.caretPos;
caretPos.text = ‘[‘+tag+’]’+caretPos.text+'[/’+tag+’]’;
} else {
var txt = document.getElementById(‘message’);
txt.value = (txt.value).substring(0, txt.selectionStart) + “[“+tag+”]” + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + “[/”+tag+”]” + (txt.value).substring(txt.selectionEnd, txt.textLength);
}
return;
}
function storeCaret(TextAreaContent) {
if (TextAreaContent.createTextRange) TextAreaContent.caretPos = document.selection.createRange().duplicate();
}
HTML:
[CODE]
<input type=”button” value=”b” onclick=”addtag(‘b’)” /><br />
<textarea name=”message” id=”message” rows=”15″ cols=”76″ onselect=”storeCaret(this);” onclick=”storeCaret(this);” onkeyup=”storeCaret(this);”></textarea>