Script Last Updated: Sunday, August 9th, 2009
Documentation Last Updated: Sunday, August 16th, 2009
Demo Last Updated: Saturday, August 15th, 2009
Parses Bulletin Board Code into a textarea form element with great ease. This script will insert some BBCode where the selection is located in a textarea form field. There is also an additional function for link BBCode with prompt feature. You may easily add more.
If you want to just copy and paste the code instead of downloading it, use this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
function addtag(tag,textarea) {
var txt = document.getElementById(textarea);
if(document.selection) {
txt.focus();
sel = document.selection.createRange();
sel.text = '[' + tag + ']' + sel.text + '[/' + tag + ']';
} else if(txt.selectionStart || txt.selectionStart == '0') {
txt.value = (txt.value).substring(0, txt.selectionStart) + "[" + tag + "]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/" + tag + "]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
} else {
txt.value = '[' + tag + '][/' + tag + ']';
}
return;
}
function addurltag(textarea) {
var txt = document.getElementById(textarea);
var link = prompt("Type the address:", "http://");
if(link.length == 0 || link == "http://") {
return;
} else {
var link = "=" + link;
var text;
var sel2 = "";
if(document.selection) {
txt.focus();
sel = document.selection.createRange();
sel2 = sel.text;
} else if(txt.selectionStart || txt.selectionStart == '0') {
sel2 = (txt.value).substring(txt.selectionStart, txt.selectionEnd);
}
if(sel2.length > 0) {
text = sel2;
} else {
text = prompt("Enter the link text:", "");
}
}
if(document.selection) {
txt.focus();
sel = document.selection.createRange();
sel.text = "[url" + link + "]" + text + "[/url]";
} else {
txt.value = (txt.value).substring(0, txt.selectionStart) + "[url" + link + "]" + text + "[/url]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
}
return;
} |
199 Unique Visitors