Thanks, that really got me started, I have fixed the errors and added a keepHTML parameter so that I can choose whether I want just plain text or not.
function HTMLFieldGetSelectedText(keepHTML)
{
var rng=null,retval='';
var ce=document.getElementById('CE_Editor_ID');
if(ce&&ce.IsReady)
{
if (ce.GetSelection && ce.GetSelection().createRange)
{
rng=ce.GetSelection().createRange();
retval=keepHTML?rng.htmlText||'':rng.text;
}
else if (ce.GetSelection)
{
rng=ce.GetSelection();
if (rng.rangeCount > 0 && window.XMLSerializer)
{
rng=rng.getRangeAt(0);
retval=keepHTML?new XMLSerializer().serializeToString(rng.cloneContents()):rng.cloneContents().textContent;;
}
}
}
return retval;
}