Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Highlight A Word In Javascript. Help!, BBCode
arcticsnpr
post Dec 23 2006, 09:43 PM
Post #1


Newbie [Level 2]
**

Group: Members
Posts: 27
Joined: 5-April 06
Member No.: 21,363



Hi,
I'm making a forum right now, and i'm having some trouble with BBCodes. I want it so when they click a button it will add the bbcode and highlight (or place the cursor between) the code. Let me clarify, I want a button to be clicked, it adds code to the textarea and places the cursor between the tags.

Example:
CODE

[b] (cursor here)  [/b]
[b] | [/b]

The cursor is between the two tags. I REALLY appreciate it, i've search so long with no luck.
Go to the top of the page
 
+Quote Post
2091
post Jan 2 2007, 10:20 AM
Post #2


Member [Level 3]
******

Group: Members
Posts: 90
Joined: 8-October 04
From: vienna
Member No.: 1,509



QUOTE(arcticsnpr @ Dec 23 2006, 10:43 PM) *

Hi,
I'm making a forum right now, and i'm having some trouble with BBCodes. I want it so when they click a button it will add the bbcode and highlight (or place the cursor between) the code. Let me clarify, I want a button to be clicked, it adds code to the textarea and places the cursor between the tags.

Example:
CODE

[b] (cursor here)  [/b]
[b] | [/b]

The cursor is between the two tags. I REALLY appreciate it, i've search so long with no luck.



you have to work with styles like this:
CODE

<html>
<body bgcolor=black text=#FFA500>

<style type=text/css>
body{
background:#000000;
color:#FFA500;
}

.democlass{
background:#FFA500;
color:#000000;
}

.democlass2{
background:#00A500;
color:#FF0000;
}

#demotable {
background:#FF0000;
color:#F0F0F0;
}
</style>

<table id=demotable>
<tr>
<td class="democlass" id='demoWindow' onMouseover=java script:switcher(this.id) onMouseout=java script:switcher(this.id)>try me</td></tr>

</table>

<script language="JAVASCRIPT">

function switcher(item){
if(document.getElementById(item).className == "democlass2")
document.getElementById(item).className = "democlass";
else
document.getElementById(item).className = "democlass2";
}
</script>
</body>
</html>


smile.gif

-- -- --

sorry... i missunderstood... you want to change the text BETWEEN the bold tag..

simple write a funtion witch looks like that:

CODE

<html>
<body>
outter html <div id="innner" onmouseover=java script:switchtext(this.id)>inner html - mouse over</div>

<script language="JAVASCRIPT">

function switchtext(item){
    var newtext = document.createTextNode("this is the real thing");
    document.getElementById(item).replaceChild(newtext, document.getElementById(item).firstChild);
}

</script>
</body>
</html>


This post has been edited by 2091: Jan 2 2007, 10:29 AM
Go to the top of the page
 
+Quote Post
apacheNewbie
post Jan 3 2007, 09:38 PM
Post #3


Newbie [Level 2]
**

Group: Members
Posts: 30
Joined: 23-November 06
Member No.: 33,877



You can try this one:
CODE

var beginText = textarea.value.substr(0, textarea.selectionStart);
var endText = textarea.value.substr(textarea.selectionEnd);
var cursorPos = textarea.selectionStart;

textarea.value = beginText + beginCode + endCode + endText;
//Change beginCode and endCode with the symbol that you want
//Example beginText + [X] + [/X] + endText

//to put the cursor in the middle
if (textarea.setSelectionRange)
{
    textarea.setSelectionRange(cursorPos + beginCode.length, cursorPos + beginCode.length);
    textarea.focus();
}


Does not work on all browser. But I think it works on mozilla and IE
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Javascript Slideshow Tutorial(3)
  2. Javascript Close Window(12)
  3. One Click Copy And Paste To Clipboard(5)
  4. Adding Rows & Columns In Html Table Using Javascript(1)
  5. I'm Making My Own Javascript Only Rpg :d(7)
  6. What's The Relationship Between Javascript And Java(5)
  7. Javascript : No Right Click Script !@(12)
  8. Hiding <div> Boxes With Javascript(8)
  9. A Simple Javascript Help Required(3)
  10. Help With Javascript Calculator On My Website Please!(1)
  11. My Little Javascript(0)
  12. How Do You Make A Javascript Calculator?(11)
  13. Help With Javascript Calculator Returning "nan"(2)
  14. Great Javascript Script Source(2)
  15. Web Applications: J2ee Or Javascript/css/html(1)
  1. Opera Browser + Javascript + Embeded Sound(0)
  2. Javascript - What's Your Browser?(3)
  3. Javascript Events Not Working For Ie(6)
  4. I`m New To Javascript.(5)
  5. Special Wii Javascript(2)
  6. Javascript Error(2)
  7. Is It Possible To Create A Web Based Mmo In Javascript?(4)
  8. Capturing Username Of Computer(3)
  9. Javascript Object Node Referencing Help(5)
  10. Flash And Javascript Interaction(1)
  11. Document.write & Noscript Questions (javascript)(1)
  12. Java Vs Javascript(11)
  13. Adjusting Rows/cols Of Frames In Frameset Using Javascript Is Not Working In Firefox 3 Is Not Working(4)


 



- Lo-Fi Version Time is now: 24th July 2008 - 06:31 AM