Jump to content
xisto Community
Sign in to follow this  
arcticsnpr

Highlight A Word In Javascript. Help! BBCode

Recommended Posts

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:

[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.

Share this post


Link to post
Share on other sites

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:

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

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

:lol:

 

-- -- --

 

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

 

simple write a funtion witch looks like that:

 

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

Edited by 2091 (see edit history)

Share this post


Link to post
Share on other sites

You can try this one:

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 middleif (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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.