Forum Moderators: open
I tried to write a text editor a wjile ago used this to find where the cursor was on the page, from there you could work what your cursor had selected or where it was at any time and then work out how long the value of the text box or table cell is and insert the relevant value into there.
Have a look at this page, it helped me.
[quirksmode.org...]
here is a function i made to insert tags into relevant parts of the page.
function insertTag(what_type)
{
var totalString; //store original string so that we can manipulated
var selectedString; //the selected string
var totalLength; //total length of the string
var selectedLength; //length of the selected area
var indexStart; //index of the string selected
var indexFinished; //last index of the string selected
var firstTextValue; //the first part of the string before index
var lastTextValue; //the last part of the string after index
totalString = document.all("BodySpan").innerText;
selectedString = document.selection.createRange().text;
totalLength = document.all("BodySpan").innerText.length;
selectedLength = document.selection.createRange().text.length;
indexStart = totalString.indexOf(selectedString);
indexFinished = indexStart + selectedLength;
firstTextValue = totalString.substring(0, indexStart);
lastTextValue = totalString.substring(indexFinished, totalLength);
if(what_type == 'pink')
{
selectedString = "<span class="+String.fromCharCode(34)+"style1"+String.fromCharCode(34)+">"+selectedString+"</span>";
}
document.all("BodySpan").innerText = firstTextValue + selectedString + lastTextValue;
document.form1.text1.value = firstTextValue + selectedString + lastTextValue;
//document.form1.text1.value = document.all("BodySpan").innerText;
document.form1.submit();
}