Hey there, i am making cPanel to the websites i cr8..
so wanna it easy to the user to edit the texts..
gonna tell u what i have done.
the user have cPanel page...with text form, when he type the text and confirm some script automatic save this text into .txt file....other script in the home page import the text from that.txt file...

its working perfect the problem is if the user wanna add header or some thing..how i make the editor able to make the text head or paragraph or or or?

so what i want is adding some buttons in the text form...when i select word and press on button "HEADER" the codes <h1> </h1> automatic be added beside the selected word?!
and when i press "Break"
Automatic add <br /><hr width="50%" /><br /> ??? and so on??

Edited by DarkBerzerk™: n/a

7 Years
Discussion Span
Last Post by DarkBerzerk™

Hope this code will help..
u can modify it as per ur requirement.

<form NAME="myForm">
<input TYPE="button" VALUE="Line Break" ONCLICK="insertString('</br>')">
<input TYPE="button" VALUE="H1 Tag" ONCLICK="insertString('<h1></h1>')">
<textarea NAME="myTextArea" ROWS="5" COLS="100"></textarea> 
<script LANGUAGE="Javascript">
var globalCursorPos=0; // global variabe to keep track of where the cursor was

function caret(node) {
 /* without node.focus() IE will returns -1 when focus is not on node */
 if(node.selectionStart) return node.selectionStart;
 else if(!document.selection) return 0;
 var c		= "\001";
 var sel	= document.selection.createRange();
 var dul	= sel.duplicate();
 var len	= 0;
 sel.text	= c;
 len		= (dul.text.indexOf(c));
 sel.text	= "";
 return len;

function setCursorPos() { 
 globalCursorPos = caret(myForm.myTextArea); 

function insertString(stringToInsert) {
 var firstPart = myForm.myTextArea.value.substring(0, globalCursorPos);
 var secondPart = myForm.myTextArea.value.substring(globalCursorPos, myForm.myTextArea.value.length);
 myForm.myTextArea.value = firstPart + stringToInsert + secondPart;
Votes + Comments
Answered The Question!

WOW AMAZING SEXY NICE :D...the last problem is in the headers and paragraphs..i will have to make button for start tag and other for end tag :D

Edited by DarkBerzerk™: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.