BBcode and javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

BBcode and javascript

Post by Jim_Bo »

Hi,

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; 
 } 
}
 
Thanks
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: BBcode and javascript

Post by JAB Creations »

Simply replace the static element's ID with a variable and then instead of the static ID put a JavaScript variable. Then when you call the function pass the form's ID as a parameter...make that parameter (the form or textarea's ID) the variable. That's all there is to it! 8)
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Re: BBcode and javascript

Post by Jim_Bo »

Hey,

Im not following that well, im not good with javascript just yet..

Is it posible to get some code examples?


Thanks
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: BBcode and javascript

Post by JAB Creations »

Why should we write something from scratch for you when such things have been written how many hundreds of times?
http://www.google.com/search?q=JavaScri ... =firefox-a

Once you have written something and can show you've made a reasonable effort to debug it yourself...then you'll want to post asking for help with code. There are countless tutorials out there. For something this basic you should setup your own test case and mess around with the code you find online.

I'll give you a starting hint, parent.something is equivalent to the name or id of a frame (I can't remember which off the top of my head).
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Re: BBcode and javascript

Post by Jim_Bo »

Hey,

Wasnt asking to have a script writen for me .. I asked for some examples of what you ment..


Thanks
Post Reply