BBcode and javascript
Posted: Fri Dec 05, 2008 12:08 am
Hi,
How is it posible to make this javascript work for multiple textareas within a single form?
Thanks
How is it posible to make this javascript work for multiple textareas within a single form?
Code: Select all
function bbcode(open, end){
var tArea = document.description.description;
var isIE = (document.all)? true : false;
var open = (open)? open : "";
var end = (end)? end : "";
if(isIE){
tArea.focus();
var curSelect = document.selection.createRange();
if(arguments[2]){
curSelect.text = open + arguments[2] + "]" + curSelect.text + end;
}else{
curSelect.text = open + curSelect.text + end;
}
}else if(!isIE && typeof tArea.selectionStart != "undefined"){
var selStart = tArea.value.substr(0, tArea.selectionStart);
var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length);
var curSelection = tArea.value.replace(selStart, '').replace(selEnd, '');
if(arguments[2]){
tArea.value = selStart + open + arguments[2] + "]" + curSelection + end + selEnd;
}else{
tArea.value = selStart + open + curSelection + end + selEnd;
}
}else{
tArea.value += (arguments[2])? open + arguments[2] + "]" + end : open + end;
}
}