0

Is it possible to control where in an input typing starts on focus?

e.g.

<input type="text" value="(+44)" id="phone_number" /> 

I need the user's typing to begin after the existing value, but leave the option to backspace and delete.

Something like:

$(document).ready(function(){
 $('#phone_number').focus(function(){
  //place type start after whatever value already exists
 });
});
Barney
  • 1,820
  • 5
  • 29
  • 50

2 Answers2

1

This can also help you to keep formatted input field

http://digitalbush.com/projects/masked-input-plugin/

 jQuery(function($){
    $("#phone_number").mask("(+44)999999");
 });

I have use 9 to add only numeric values only, else you can you * to add anything

Hiren Soni
  • 574
  • 3
  • 11
1

If you want to use jQuery, you can do:

$("input").focus(function () {
    var val = this.value;
    var $this = $(this);
    $this.val("");
    setTimeout(function () {
        $this.val(val);
    }, 1);
});

Taken from this original answer.

DEMO

Community
  • 1
  • 1
Eli
  • 14,779
  • 5
  • 59
  • 77