/    Sign up×
Community /Pin to ProfileBookmark

BBcode javascript

Hi,

With the following javascript, is it possible to make it so when you click the button to place the bbcode in the text area, have the cursor start between the tags?

[code]function bbcode(open, end){
var tArea = document.addcars.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;
}
}[/code]

THanks

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @jim_bo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...