js part of opperating the bbcode

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddiki
    Contributor
    • Jan 2009
    • 290

    js part of opperating the bbcode

    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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    http://bytes.com/topic/javascript/an...ition-textarea may help.

    Comment

    • flydev
      New Member
      • Feb 2008
      • 33

      #3
      I use this, its from simpleBBCode by Brady Mulhollem, the function accepts the open and close tags.

      Code:
      function addTags(Tag, fTag) 
      { 
        var obj = document.formname.element; 
        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 (obj != "undefined")  // Firefox 
        { 
          	var longueur = parseInt(obj.textLength); 
      	var selStart = obj.selectionStart; 
      	var selEnd = obj.selectionEnd; 
      
      	obj.value = obj.value.substring(0,selStart) + Tag + obj.value.substring(selStart,selEnd) + fTag; 
        } 
        
        else obj.value += Tag + fTag; 
      
        obj.focus(); 
      }

      Comment

      Working...