Created
May 10, 2012 03:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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