funhunter
02-03-2006, 07:41 AM
hi, I'm a new comer for DOM scripting, I have a piece of code :
function insert_text(text, movestart, moveend)
{
if (document.getElementById)
{
var editbox=document.getElementById('textbox');
}
else if (document.all)
{
var editbox= document.all['textbox'];
}
editbox.focus();
if (typeof(editbox.selectionStart) != 'undefined')
{
var opn = editbox.selectionStart + 0;
editbox.value = editbox.value.substr(0, editbox.selectionStart) + text + editbox.value.substr(editbox.selectionEnd);
if (movestart === false)
{// do nothing }
else if (typeof movestart != 'undefined')
{
editbox.selectionStart = opn + movestart;
editbox.selectionEnd = opn + text.vBlength() - moveend;
}
else
{
editbox.selectionStart = opn;
editbox.selectionEnd = opn + text.vBlength();
}
}
else if (document.selection && document.selection.createRange)
{
var sel = document.selection.createRange();
sel.text = text.replace(/\r?\n/g, '\r\n');
if (movestart === false)
{
// do nothing
}
else if (typeof movestart != 'undefined')
{
sel.moveStart('character', -text.vBlength() +movestart);
sel.moveEnd('character', -moveend);
}
else
{
sel.moveStart('character', -text.vBlength());
}
sel.select();
}
else
{
// failed - just stuff it at the end of the message
editbox.value += text;
}
}
But I dont have any reference for selection, moveStart,MoveEnd, selectionStart and selectionEnd methos or property.I have search in all DOM level2 document.Plz help!
function insert_text(text, movestart, moveend)
{
if (document.getElementById)
{
var editbox=document.getElementById('textbox');
}
else if (document.all)
{
var editbox= document.all['textbox'];
}
editbox.focus();
if (typeof(editbox.selectionStart) != 'undefined')
{
var opn = editbox.selectionStart + 0;
editbox.value = editbox.value.substr(0, editbox.selectionStart) + text + editbox.value.substr(editbox.selectionEnd);
if (movestart === false)
{// do nothing }
else if (typeof movestart != 'undefined')
{
editbox.selectionStart = opn + movestart;
editbox.selectionEnd = opn + text.vBlength() - moveend;
}
else
{
editbox.selectionStart = opn;
editbox.selectionEnd = opn + text.vBlength();
}
}
else if (document.selection && document.selection.createRange)
{
var sel = document.selection.createRange();
sel.text = text.replace(/\r?\n/g, '\r\n');
if (movestart === false)
{
// do nothing
}
else if (typeof movestart != 'undefined')
{
sel.moveStart('character', -text.vBlength() +movestart);
sel.moveEnd('character', -moveend);
}
else
{
sel.moveStart('character', -text.vBlength());
}
sel.select();
}
else
{
// failed - just stuff it at the end of the message
editbox.value += text;
}
}
But I dont have any reference for selection, moveStart,MoveEnd, selectionStart and selectionEnd methos or property.I have search in all DOM level2 document.Plz help!