SEO Forums


Chess, Go & Poker Server









                                          
User   Password   remember   (register)  ?

How to insert BBcode / Textarea

Poker, chess & Go world championship

Back to javascript.


admin    (2008-10-16)
How to insert BBcode / Textarea


How to insert BBcode tags around the selected text in a textarea ?

After having searched scripts to answer my question (more or less simple codes with the Caret method and so on) and encountered some problems & bugs, I have rewritten one small code that works fine on these forums, here is the result :


<script language="javascript" type="text/javascript">

function addText(Text,Message)
{
  var obj = document.form.message;

  obj.focus();

  if (document.selection && document.selection.createRange)  // Internet Explorer
  {
sel = document.selection.createRange();
if (sel.parentElement() == obj)  sel.text = Text;
  }

  else if (typeof(obj) != "undefined")  // Firefox
  {
var longueur = parseInt(obj.value.length);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0,selStart) + Text + obj.value.substring(selEnd,longueur);
  }

  else obj.value += Text;

  obj.focus();
}


function addTags(Tag,fTag,Message)
{
  var obj = document.form.message;

  obj.focus();

  if (document.selection && document.selection.createRange)  // Internet Explorer
  {
sel = document.selection.createRange();
if (sel.parentElement() == obj)  sel.text = Tag + sel.text + fTag;
  }

  else if (typeof(obj) != "undefined")  // Firefox
  {
var longueur = parseInt(obj.value.length);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0,selStart) + Tag + obj.value.substring(selStart,selEnd) + fTag + obj.value.substring(selEnd,longueur);
  }

  else obj.value += Tag + fTag;

  obj.focus();
}

</script>



<?  // In example, a part of the form  ?>

<form method="post" name="form" action="...">

<a title="Bold : [B ][/B ]" onmousedown="addTags('[B ]','[/B ]')" style="background-color:#F7F7F7; font-size:10pt; border: outset white 1px;">&nbsp;<b>B</b>&nbsp;</a>

<img src="images/smilies/smile.gif" title="[:) ]" onmousedown="addText('[:) ]')">

<textarea wrap="VIRTUAL" name="message" cols="50" rows="10"></textarea>

</form>




(more options below)

*me    (2008-11-24 22:09:55)
Testing the input

This could be handy

Don't like the URL though - a prompt would be better.

I could tweak this


*me    (2008-12-27 19:23:04)
Test!

Well! Not too bad!


*71c892    (2009-02-24 18:37:51)
Select Boxes

how would you go about adding select boxes for font size and color


*622617    (2009-06-23 22:47:40)
Select Box

<select name="color" id="color" class="autowidth"><option selected="selected" value="">Color</option>
<option value="Red" onmousedown="addTags('[color=red ]','[/color ]')"><font color='red'>Red</font></option></select>



*de2fe0    (2009-07-10 19:34:30)
Bugs fixed

Finally, the script has been corrected, the new version works fine with IE8, Firefox 3.5, Google Chrome and Opera. Thanks Liam !


*test_it    (2010-04-11 14:11:48)
How to insert BBcode / Textarea

this is a test

hi

hi again

in preview is so fine


*moxoje    (2010-05-03 22:16:01)
8 years ago

Thank you verry much. This is great !!


*gufaxo    (2010-05-07 18:50:57)
8 years ago

jjj
srtjn 
fdghm
edmrfn
dgh


*lupupe    (2010-07-26 21:27:27)
8 years ago

Hello... Just a test. Its kinda useful!


*jaxori    (2010-07-29 00:18:46)
8 years ago

<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">Fast answer</span> Rápida respuesta</span>


*fizifu    (2010-08-25 18:23:33)
How to insert BBcode / Textarea

<script language="javascript" type="text/javascript">

function addText(Text, Message)
{
  var obj = document.form.message;

  obj.focus();

  if (document.selection && document.selection.createRange)  // Internet Explorer
  {
sel = document.selection.createRange();
if (sel.parentElement() == obj)  sel.text = Text;
  }

  else if (typeof(obj) != "undefined")  // Firefox
  {
var longueur = parseInt(obj.value.length);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0, selStart) + Text + obj.value.substring(selEnd, longueur);
  }

  else obj.value += Text;

  obj.focus();
}


function addTags(Tag, fTag, Message)
{
  var obj = document.form.message;

  obj.focus();

  if (document.selection && document.selection.createRange)  // Internet Explorer
  {
sel = document.selection.createRange();
if (sel.parentElement() == obj)  sel.text = Tag + sel.text + fTag;
  }

  else if (typeof(obj) != "undefined")  // Firefox
  {
var longueur = parseInt(obj.value.length);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0, selStart) + Tag + obj.value.substring(selStart, selEnd) + fTag + obj.value.substring(selEnd, longueur);
  }

  else obj.value += Tag + fTag;

  obj.focus();
}

</script>



<?  // In example, a part of the form  ?>

<form method="post" name="form" action="...">

<a title="Bold : [B ][/B ]" onmousedown="addTags('[B ]','[/B ]')" style="background-color:#F7F7F7; font-size:10pt; border: outset white 1px;">&nbsp;<b>B</b>&nbsp;</a>

<img src="images/smilies/smile.gif" title="[:) ]" onmousedown="addText('[:) ]')">

<textarea wrap="VIRTUAL" name="message" cols="50" rows="10"></textarea>

</form>


*redibu    (2010-09-28 01:11:37)
8 years ago

dit is een test


*tuveko    (2011-02-03 12:42:05)
7 years ago

this is an
bbcode
test


*matthew    (2011-03-24 16:26:13)
7 years ago

This is awesome code, I just used it in a calendar program I am making for myself, but I have a question if you wouldn't mind helping me out.

Say for example I have a body of text and I click somewhere in the middle of it and call the addText function, text would be added in the middle of the text (which is what I want), if I call the addText function again however, the text is added at the end of the body of text.

how can I prevent that from happening? I would like for the second call of the function to insert the text right after the first call.

Kalzenith(at)gmail.com


*diziru    (2011-04-02 23:52:29)
7 years ago

essai encore un essai un essai unessai


*posoje    (2011-04-03 11:45:09)
How to insert BBcode / Textarea

Very Nice!
Thanks a
LOT



*pamefu    (2011-05-09 09:10:12)
7 years ago

<script language="javascript" type="text/javascript">

function addText(Text, Message)
{
  var obj = document.form.message;

  obj.focus();

  if (document.selection && document.selection.createRange)  // Internet Explorer
  {
sel = document.selection.createRange();
if (sel.parentElement() == obj)  sel.text = Text;
  }

  else if (typeof(obj) != "undefined")  // Firefox
  {
var longueur = parseInt(obj.value.length);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0, selStart) + Text + obj.value.substring(selEnd, longueur);
  }

  else obj.value += Text;

  obj.focus();
}


function addTags(Tag, fTag, Message)
{
  var obj = document.form.message;

  obj.focus();

  if (document.selection && document.selection.createRange)  // Internet Explorer
  {
sel = document.selection.createRange();
if (sel.parentElement() == obj)  sel.text = Tag + sel.text + fTag;
  }

  else if (typeof(obj) != "undefined")  // Firefox
  {
var longueur = parseInt(obj.value.length);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0, selStart) + Tag + obj.value.substring(selStart, selEnd) + fTag + obj.value.substring(selEnd, longueur);
  }

  else obj.value += Tag + fTag;

  obj.focus();
}

</script>



<?  // In example, a part of the form  ?>

<form method="post" name="form" action="...">

<a title="Bold : [B ][/B ]" onmousedown="addTags('[B ]','[/B ]')" style="background-color:#F7F7F7; font-size:10pt; border: outset white 1px;">&nbsp;<b>B</b>&nbsp;</a>

<img src="images/smilies/smile.gif" title="[:) ]" onmousedown="addText('[:) ]')">

<textarea wrap="VIRTUAL" name="message" cols="50" rows="10"></textarea>

</form>


*zipume    (2012-04-23 11:40:24)
6 years ago

nitin matkar i cers gs snsf


*vevaca    (2012-04-30 13:40:56)
6 years ago

bbbbbbb  aaaa aa aaa aaaaa aaa aa


*kopomi    (2012-05-15 09:43:16)
6 years ago

prova per la tua
festa tutto ok
ciao


*xuzile    (2012-05-24 06:15:44)
How to insert BBcode / Textarea

class Demo{
  public static void main(String args[])
}


*vexace    (2012-05-24 06:36:44)
6 years ago

hello


        function surroundText(text1, text2, textarea)
        {
                if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
                {
                        var caretPos = textarea.caretPos, temp_length = caretPos.text.length;
                        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
                        if (temp_length == 0)
                        {
                                caretPos.moveStart("character", -text2.length);
                                caretPos.moveEnd("character", -text2.length);
                                caretPos.select();
                        }
                        else
                                textarea.focus(caretPos);
                }
                else if (typeof(textarea.selectionStart) != "undefined")
                {
                        var begin = textarea.value.substr(0, textarea.selectionStart);
                        var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
                        var end = textarea.value.substr(textarea.selectionEnd);
                        var newCursorPos = textarea.selectionStart;
                        var scrollPos = textarea.scrollTop;
                        textarea.value = begin + text1 + selection + text2 + end;                     
                        if (textarea.setSelectionRange)
                        {
                                if (selection.length == 0)
                                        textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
                                else
                                        textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
                                        textarea.focus();
                        }
                        textarea.scrollTop = scrollPos;
                }
                else
                {
                        textarea.value += text1 + text2;
                        textarea.focus(textarea.value.length - 1);
                }
        }
        function storeCaret(text)
        {
                if (typeof(text.createTextRange) != "undefined")
                text.caretPos = document.selection.createRange().duplicate();
        }





*kexapo    (2012-08-26 17:40:01)
6 years ago

How to insert BBcode / Textarea


*xuvete    (2012-10-15 16:15:49)
6 years ago

lol nice dat het werkt ? dan



*tazore    (2012-12-21 19:21:44)
5 years ago

Testing the add textarea bbcode


*pkahmbqod    (2013-04-27 10:31:31)
oakley polarized hijinx sunglasses

Here's what Yelpers have to say about Shopping in 97301SLAB Handcrafted Soap (Salem) "My girlfriend and I spent way more time than was necessary one afternoon in this store. I do believe we smelled very single bar of soap that was available,." moreAvva Cigars Wine (Salem) "Avva Cigars has the biggest and best-stocked humidor between Portland and CA. It is a literal walk-in room, filled with great cigars. Want brand new." moreAddictions Body Piercing Tattoo (Salem) "I took my 4 months old baby to this place to get her ears pierced. I took her to this place instead of to Claires because I had bad experience there, my." moreSalem Printing Blueprint (Salem) "There are a lot of companies to choose from in the highly competitive business of printing. First the good: selection, prices, location, parking, strange." more oakley polarized hijinx sunglasses ht*p://www.sunglasses-soaho.org/oakley-polarized-hijinx-sunglasses-p-555.html


*jitija    (2014-06-29 00:33:18)
4 years ago

sdsd ff  fds fsf  sdsdsdsd  dsd sd


*jadila    (2014-10-08 17:09:59)
4 years ago

</script>
<? // In example, a part of the form ?>
<form method="post" name="form" action="...">
<a title="Bold : [B ][/B ]" onmousedown="addTags
('[B ]','[/B ]')" style="background-color:#F7F7F7;
font-size:10pt; border: outset white
1px;">&nbsp;<b>B</b>&nbsp;</a>
<img src="images/smilies/smile.gif" title="[:) ]"
onmousedown="addText('[:) ]')">
<textarea wrap="VIRTUAL" name="message"
cols="50" rows="10"></textarea>
</form>
Previe


*zekaga    (2014-12-29 07:20:08)
3 years ago

I don't know if your realize it or not, but the sites making the real big AdSense money usually have a following that doesn't depend on the search engines. Internet mavens like Chris Pirillo or Joel Comm have been on the Internet a while and have followings for their websites. Therefore they can consistently make six figures with AdSense.
Moncler Jackets


*juzimo    (2015-01-18 20:36:36)
3 years ago

dggddgdggffg gfffffffffff gfffffffffffff gfffffffffffffffffffffffffffffffffffffffff gffffffffffffffff


*nipizo    (2018-05-13 08:09:53)
[a href"#"]tyuiop[/a]

here is a link here too [a href"#"]tyuiop[/a]


See also


ficgs
More websites

You must register to see these links, as this is a collaborative page, then you may change the order of the links by clicking the icons before the titles.



admin
Other websites

The following links might be less relevant, please change their ranks if you find them useful.


 Parse BBCode Into Textarea | JavaScript Forms | Hot Scripts
hotscripts > listing/parse bbcode into textarea

 BBcode, Text Area With Ajax
icyphoenix > viewtopic.php?t=3539

Thanks for bringing it up, I think its good to see alternative...
Hello all again xD I am stray in internet xD and I fund a...

 bbcode insert only in IE? - Dynamic Drive Forums
dynamicdrive > forums/s

Unfortunately you will have to use createTextRange and such...

 Insert Text Into Form Using Javascript PHP Put Content In Textarea Field Link
wallpaperama > forums/insert text into form using javascript php put content in

Share this page by putting this URL in your comments to other...
To embed this topic, just copy the code from the...

 Parse BBCode Into Textarea : JavaScript Scripts and Programs Form Processors Scripts Directory
advancescripts > detailed/16538

No part of this website may be reproduced, copied and/or distributed...
Trademarks are property of their respective owners Site Developed...

 » Javascript » Corpocrat Blog
corpocrat > category/javascript

how to strip special characters with jQuery form...
Troubleshooting BSNL Broadband related Issues in your Telephone...

 Insert into a textarea - CodingForums.com
codingforums > s

How can I manipulate the selection and the caret in an input...

 TextArea - CreateRange, caretPos [Archive] - WebDeveloper.com
webdeveloper > forum/archive/index.php/t 49058

look at the on events focus is a method of putting the cursor...

 BBCode Advanced (bbcode, jquery) - PHP Classes
phpclasses > browse/package/2867

 Writing bbcode script: textarea problem and IE7 oddities - Dev Shed
forums.devshed > javascript development 115/writing bbcode script textarea probl

In any case, do you mind if I closely incorporate your code in...
Warburton's the largest independently owned bakery in the UK faced a...
Create the Optimal Architecture for your Critical...

 Tag-insert in textarea - DevX.com Forums
forums.devx > s

Nokia Makes It Easier to Create, Distribute Apps for its Symbian...
Grid, HPC Cluster and Cloud, Part 2: A Developer...

 Nazgum’s Blog » Blog Archive » BBCode with Ruby on Rails, Part 2
nazgum > 2008/03/23/bbcode with ruby on rails part 2

 How to insert text into text area - Web Hosting
vodahost > vodatalk/adding elements your website/10440

 Insert Text into TextArea on Client - HTML Forums - Free Webmaster Forums and Help Forums
htmlforums > client side scripting/t insert text into textarea on client 97006

Most browsers excluding IE will allow you to select and drag any...
As far as I know, it is not possible to detect where the cursor...

 BBCode - SWiK
swik > BBCode

Take credit for any changes I made as an anonymous user...
BBComposer : Editeur BBCode, XHTML, Wiki et XBBCode intégré à...

 Insert Into Text Area - TalkPHP
talkphp > javascript ajax e4x/3394 insert into text area

The basic usage of PHPTAL, a XML/XHTML template library for...
Vulnerable methods and the areas they are commonly trusted...

 Insert Text From TEXTAREA into MySQL - Usenet Forums
usenet forums > php language/29379 insert text textarea into mysql

Euhm, I have no clue what a TEXAREA is, but for a textarea's it's...
Hi, I'm trying to figure out how to INSERT/UPDATE text from...
Rik, Could you give me an example? I'm not following...

 BBCode extension for BlogEngine.NET 1.2
madskristensen > post/BBCode extension for BlogEngineNET 12.aspx

The opinions expressed herein are my own personal opinions and do not...

 Free bbcode Download - bbcode Software
wareseeker > free bbcode

var pageOptions = { 'pubId' : 'pub-8098918000470057', 'channel' :...
- Post editor replicates the post editing environment in forums -...

 artday network - FAQ
artday > modules/xoopsfaq/index.php?cat id=1

 Trying to insert </textarea> - Subdreamer CMS
subdreamer > forum/s

 JavaScript: Prompt User and Insert to textarea - Pixel2Life Forum
pixel2life > forums/index.php?s

1 User(s) are reading this topic (1 Guests and 0 Anonymous...
Group: Members Posts: 277 Joined:...

 How to insert text area value into db(mysql) without new line? - SitePoint Forums
sitepoint > forums/s

Notice: This Website takes advantage of web standards that your...

 Javascript insert text into textarea
110mb > forum/javascript insert text into textarea t29703.0

BTW if your having trouble with actual insert into the Textarea you...
So really i just need to edit what is in the topic i linked...
Quote from: RBCFAQS on April 29, 2008, 10:45:33...

 Textarea BB Code
search.code head > F Textarea BB Code 977676

 How to insert textarea contents in asp.net & Sql Server - CodeGuru Forums
codeguru > FORUM/s

[Updated] C++ Programming: Memory Mapped Files using...
Hi, In my project i am using Textarea (HTML Tag) as...

 WYSIWYG BBCode Editor Demo
php login script > bbdemo.php

 JAVASCRIPTS :: Insert Text In Textarea On Right Click In Java Script
bigresource > JAVASCRIPTS insert text in textarea on right click in java script

I found that, insertRow, insertCell, is a bug of Mac IE,...

 Weborum Webmaster Forum > Enhanced User input form
forum.weborum > lofiversion/index.php/t2030

 [whatwg] What exactly is contentEditable for?
lists.whatwg > htdig.cgi/whatwg whatwg.org/2005 August/004543

The functionality provided from a user's point of view may be very...
I'm not disputing the fact that there is an unfortunate demand for...

 TinyMCE Forum / BBCode?!?
tinymce.moxiecode > punbb/viewtopic.php?id=849

bbcode-parser (my testpage, you can insert text with bb-code into...
// Google Analytics with Async load, DONT CLOG MA BROWSER...
Provided for developers anywhere, everywhere, anytime and with...

 INSERT DATA FROM MULTIPLE TEXTAREAS IN THE FORM TO THE DATABASE - bytes
bytes > groups/asp/820347 insert data multiple textareas form database

 Almsamim - web developer • View topic - [BETA] Almsamim WYSIWYG editor v0.0.5 for phpBB3
almsamim > beta almsamim wysiwyg editor v0 0 5 for phpbb3 t111

 [RESOLVED] retrieving data from a textarea - VBForums
vbforums > s

thank you very much john tindell, it works! you're so...
Article :: Domain-Specific Languages: An Introductory...
Just split the value up by n and insert them into the...

 JavaScript - Insert Text Into A Textbox | DreamInCode.net
dreamincode > forums/s

 Allow Image BB Code - GamersHQ.com
gamershq > forum/site suggestions/681 allow image bb code

ame_toggle_view({other : 'true',post : 'true',blog : 'true',group :...
Members: 722 Threads: 2,974 Posts: 14,446 Top Poster:...

 phpBB • Information
phpbb > community/viewtopic.php?f=70&t=723495&start=45

The tracker for security issues in phpBB or validated...
View Flash Tutorials that help you with the use of...



Response  
  Smilies

Guest name   (optional)       Register for more options.



Trackbacks : If you talked about this article in your blog or website, you may instantly get a backlink 
  There's no trackback at the moment.











 

FICGS message




SEO forums and chat - Search engines optimization



 


Make your profile in the social network :

- Create groups, pages and events.
- Promote your website (free backlink).
- Keep in touch with your friends.
- Discover what your friends think about you.
- And many more features soon...

 


Pagerank       Copy this code to display your site's Pagerank




Write upside down in your blog, anywhere!
(works with Twitter, Facebook, MySpace, Youtube, MSN, Yahoo, Bebo, Hi5...)







FICGS is also a Free Internet Correspondence Games Server.

Here you can play Chess, Go & Poker Texas Holdem online for free in rated class tournaments and a unique world championship.

Free Internet Chess & Go Server


Feel free to link to this page and to FICGS chess server :