tsunami

log in
history

Javascript SetSelection

Luke Breuer
2008-10-20 04:18 UTC

function SetSelection(txt, idx, length)
{
    if (txt.createTextRange)
    {
        var range = txt.createTextRange();
        
        range.collapse(true);
        range.moveStart('character', idx);
        range.moveEnd('character', idx + length);
        range.select();
    }
    else if (txt.selectionEnd)
    {
        txt.selectionStart = idx;
        txt.selectionEnd = idx + length;
    }
}