JavaScript and client side scripting.
Moderator: General Moderators
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Fri Dec 05, 2008 12:08 am
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
JAB Creations
DevNet Resident
Posts: 2341 Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:
Post
by JAB Creations » Sat Dec 06, 2008 5:46 am
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!
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Sat Dec 06, 2008 5:17 pm
Hey,
Im not following that well, im not good with javascript just yet..
Is it posible to get some code examples?
Thanks
JAB Creations
DevNet Resident
Posts: 2341 Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:
Post
by JAB Creations » Sun Dec 07, 2008 4:41 am
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
Post
by Jim_Bo » Sun Dec 07, 2008 3:21 pm
Hey,
Wasnt asking to have a script writen for me .. I asked for some examples of what you ment..
Thanks