473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

js part of opperating the bbcode

290 100+
Hi,
I want to write a js script that will wrap any text that is hıghighted in a textarea with the bbcode bold code or italics etc.

The same way that this forum post script must work.
(actually if I could find the script I could then modify it to suit my needs which would be easier )

Anyway - I am not sure how to start because how do I detect what characters are highlighted ?.

I have looked in the source code of this page for the js but can't find it :(

Can anyone help out.
Thanks
Jan 18 '09 #1
2 1130
acoder
16,027 Expert Mod 8TB
http://bytes.com/topic/javascript/an...ition-textarea may help.
Jan 19 '09 #2
flydev
33
I use this, its from simpleBBCode by Brady Mulhollem, the function accepts the open and close tags.

Expand|Select|Wrap|Line Numbers
  1. function addTags(Tag, fTag) 
  2.   var obj = document.formname.element; 
  3.   obj.focus(); 
  4.  
  5.   if (document.selection && document.selection.createRange)  // Internet Explorer 
  6.   { 
  7.     sel = document.selection.createRange(); 
  8.     if (sel.parentElement() == obj)  sel.text = Tag + sel.text + fTag; 
  9.   } 
  10.  
  11.   else if (obj != "undefined")  // Firefox 
  12.   { 
  13.         var longueur = parseInt(obj.textLength); 
  14.     var selStart = obj.selectionStart; 
  15.     var selEnd = obj.selectionEnd; 
  16.  
  17.     obj.value = obj.value.substring(0,selStart) + Tag + obj.value.substring(selStart,selEnd) + fTag; 
  18.   } 
  19.  
  20.   else obj.value += Tag + fTag; 
  21.  
  22.   obj.focus(); 
  23.  
Jan 19 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dave Moore | last post by:
Hi All, I'd like enable visitors to my website to use bbcode and emoticons whilst entering text into a form. Are there any standard lumps of php/javascript I can use for this purpose?. In...
1
by: Rob Meade | last post by:
Hi all, Back on the bbcode parsing (again)... Having a few problems now with nested tags - it would seem that I had written my test string in a way that worked perfectly with the parser -...
1
by: 如履薄冰 | last post by:
BBcode reference: http://www.phpbb.com/phpBB/faq.php?mode=bbcode I want write a BBcode module in Python, but I'v not idea for this. Who can tell me about this arithmetic? ( I'm so sorry for my...
6
by: Thaqalainnaqvi | last post by:
IPB WARNING mysql_query() : Unable to save result set (Line: 457 of /ips_kernel/class_db_mysql.php) There appears to be an error with the database. You can try to refresh the page by clicking...
0
by: Will McGugan | last post by:
Hi, I have written a BBCode parsing module that may be of use to some people. It turns BBCode in to XHTML snippets. See the following page if you are interested... ...
8
by: Matthias S. | last post by:
hi there, i'm desperately looking for an HTML to BBCode (and vice versa) converter, either as a COM component or vbScript for use in an ASP (not .NET) web-application. i sure could write one on...
1
by: Toni | last post by:
Where can I find BBCode editor (editor for forums and blogs) for ASP.NET. I need editor like FreeTextBox (but BBCode, not HTML like FreeTextBox). I need source code or control. Where can I find it?...
8
by: raaman rai | last post by:
i am adding dynamic contents in my website. So i also want to have a news or announcements to be dynamically displayed. But for this i need to use BBCode. But in reference to this, i dont know how...
2
by: bgold12 | last post by:
I already posted this message, but it didn't work or something. So if this is a duplicate, ignore it. I just can't figure out how to install this extension. From what I understand, there needs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.