setSelectionRange Hack - Place At End
When tabbing into text field, places cursor at end of text. Useful for zipcodes in a particular area (same beginning).
by Joe Cisneros
HTML
<base target="_blank">
<input type="text" value="Press TAB"><br />
<textarea rows="8" id="txt1" style="width:400px;">
Hello
Hello
Hello
Hello
Tabbing jumps here (Press SHIFT-TAB):</textarea><br>
<label for="zipcode">Zipcode:</label> <input id="zipcode" type="text" value="933">
<div style="position:absolute;top:0;right:0;border-style:groove;"><a href="//jsfiddle.net/user/JoeSwan/">JoeSwan</a> forked from <a href="//jsfiddle.net/j6yVq/2/" target="_blank">http://jsfiddle.net/j6yVq/2/</a></div>
CSS
body { font-family: Helvetica,Arial;}
JavaScript
$("textarea,input").focusin(function() {
$(this)[0].setSelectionRange(this.value.length, this.value.length);
});
$("input:first-of-type").focus();