Skip to content

Instantly share code, notes, and snippets.

@rambuvn
Created May 10, 2012 03:23
Show Gist options
  • Save rambuvn/2650837 to your computer and use it in GitHub Desktop.
Save rambuvn/2650837 to your computer and use it in GitHub Desktop.
set cursor to end point when focus or change value of input text field
function SetEnd(txt) {
if (txt.createTextRange) {
//IE
var FieldRange = txt.createTextRange();
FieldRange.moveStart('character', txt.value.length);
FieldRange.collapse();
FieldRange.select();
}
else {
//Firefox and Opera
txt.focus();
var length = txt.value.length;
txt.setSelectionRange(length, length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment