I've answered this before: Javascript: Move caret to last character
jsFiddle: http://jsfiddle.net/ghAB9/6/
Code:
function moveCaretToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}
var textarea = document.getElementById("test");
textarea.onfocus = function() {
moveCaretToEnd(textarea);
// Work around Chrome's little problem
window.setTimeout(function() {
moveCaretToEnd(textarea);
}, 1);
};