|
|
|
|
![]() ![]() |
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. |
|
|
|
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 |
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> -- -- -- 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 |
|
|
|
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 |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 24th July 2008 - 06:31 AM |