Vanderson Ramos
Vanderson Ramos

Reputation: 341

Move cursor to end input with jquery masked input

I'm using jQuery masked input plugin, and when I take the focus of the field and return the focus (blur, focus) the cursor back to the beginning, need to always leave the cursor at the end but I can not.

$('#id_origin_zipcode').bind('focus', $.proxy(this.moveCursorToEnd, this));

moveCursorToEnd: function(e){
    var value = $('#id_origin_zipcode').val();
    $('#id_origin_zipcode').val(value);

},

Upvotes: 0

Views: 5002

Answers (1)

NoGray
NoGray

Reputation: 1149

You can set selectionStart and selectionEnd to the value length. e.g.

<input type="text" onFocus="this.selectionStart = this.selectionEnd = this.value.length;" />

Upvotes: 2

Related Questions