Set cursor at a length of 14 onfocus of a textbox

Solution 1:

IE use different approach at setting cursor position than Firefox,Opera and Chrome. It's better to make a helper function, which will do it for you. I use this one for own needs.

function setCursor(node,pos){

    node = (typeof node == "string" || node instanceof String) ? document.getElementById(node) : node;

    if(!node){
        return false;
    }else if(node.createTextRange){
        var textRange = node.createTextRange();
        textRange.collapse(true);
        textRange.moveEnd(pos);
        textRange.moveStart(pos);
        textRange.select();
        return true;
    }else if(node.setSelectionRange){
        node.setSelectionRange(pos,pos);
        return true;
    }

    return false;
}

Last thing, is to call it from your onfocus handler.

Goodluck

Solution 2:

The moveStart and moveEnd methods expects 2 parameters. The first parameter is a string (character, word, sentence or textedit). The second parameter is an integer and refers to the number of units to move. http://msdn.microsoft.com/en-us/library/ie/ms536623%28v=vs.85%29.aspx