SEO Forums















                                          
User   Password   remember     (register)  ?

How to insert BBcode / Textarea


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>



guest-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


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

Well! Not too bad!


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

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


guest-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>



guest-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 !


ficgs
Suggestions

 Parse BBCode Into Textarea | JavaScript Forms | Hot Scripts
www.hotscripts.com/listing/parse-bbcode-into-textarea/

 BBcode, Text Area With Ajax
www.icyphoenix.com/viewtopic.php?t=3539

  bbcode insert only in IE? - Dynamic Drive Forums
www.dynamicdrive.com/forums/showthread.php?t=28471

 Insert Text Into Form Using Javascript PHP Put Content In Textarea Field Link
www.wallpaperama.com/forums/insert-text-into-form-using-javascript-php-put-

 Parse BBCode Into Textarea : JavaScript Scripts and Programs Form Processors Scripts Directory
www.advancescripts.com/detailed/16538.html

  » Javascript » Corpocrat Blog
corpocrat.com/category/javascript/

  Insert into a textarea - CodingForums.com
codingforums.com/showthread.php?t=104256

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



ficgs
More suggestions

This is a collaborative page, you may change the order of these suggestions by registering, then clicking the icons before the titles.


 BBCode Advanced (bbcode, jquery) - PHP Classes
www.phpclasses.org/browse/package/2867.html

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

  Tag-insert in textarea - DevX.com Forums
forums.devx.com/showthread.php?t=5422

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

 How to insert text into text area - Web Hosting
www.vodahost.com/vodatalk/adding-elements-your-website/10440-how-insert-tex

 Insert Text into TextArea on Client - HTML Forums - Free Webmaster Forums and Help Forums
www.htmlforums.com/client-side-scripting/t-insert-text-into-textarea-on-cli

  BBCode - SWiK
swik.net/BBCode

 Insert Into Text Area - TalkPHP
www.talkphp.com/javascript-ajax-e4x/3394-insert-into-text-area.html

  Insert Text From TEXTAREA into MySQL - Usenet Forums
www.usenet-forums.com/php-language/29379-insert-text-textarea-into-mysql.ht

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

 Free bbcode Download - bbcode Software
wareseeker.com/free-bbcode/

 artday network - FAQ
artday.org/modules/xoopsfaq/index.php?cat_id=1

  Trying to insert </textarea> - Subdreamer CMS
www.subdreamer.com/forum/showthread.php?t=6827

 JavaScript: Prompt User and Insert to textarea - Pixel2Life Forum
www.pixel2life.com/forums/index.php?showtopic=32515

 How to insert text area value into db(mysql) without new line? - SitePoint Forums
www.sitepoint.com/forums/showthread.php?t=579699

 Javascript insert text into textarea
www.110mb.com/forum/javascript-insert-text-into-textarea-t29703.0.html

 Textarea BB Code
search.code-head.com/F-Textarea-BB-Code-977676

  How to insert textarea contents in asp.net & Sql Server - CodeGuru Forums
www.codeguru.com/FORUM/showthread.php?p=1189131

 WYSIWYG BBCode Editor Demo
php-login-script.com/bbdemo.php

 JAVASCRIPTS :: Insert Text In Textarea On Right Click In Java Script
www.bigresource.com/JAVASCRIPTS-insert-text-in-textarea-on-right-click-in-j

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

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

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

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

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

  [RESOLVED] retrieving data from a textarea - VBForums
www.vbforums.com/showthread.php?t=394503

 JavaScript - Insert Text Into A Textbox | DreamInCode.net
www.dreamincode.net/forums/showtopic89512.htm

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

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



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



 

March 19, 2010

 

Buttons: Facebook, Twitter, MySpace, Google, Technorati, Yahoo buzz... Ficgs Facebook Myspace Twitter Google Technorati Stumble upon Delicious Digg Yahoo buzz Wikio Furl Reddit Linkedin Squidoo Newsvine Yahoo My Web Blogmarks Comments Blinklist Email

You comment I follow : Links included in comments will be "dofollow" if your post is not an obvious spam, comments are published instantly.


Write upside down to your contacts !
(works with Facebook, Twitter, MSN, Yahoo, MySpace, Hi5, Bebo, Youtube...)







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 FICGS :