Page 1 of 1

BBcode and javascript

Posted: Fri Dec 05, 2008 12:08 am
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

Re: BBcode and javascript

Posted: Sat Dec 06, 2008 5:46 am
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)

Re: BBcode and javascript

Posted: Sat Dec 06, 2008 5:17 pm
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

Re: BBcode and javascript

Posted: Sun Dec 07, 2008 4:41 am
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).

Re: BBcode and javascript

Posted: Sun Dec 07, 2008 3:21 pm
by Jim_Bo
Hey,

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


Thanks