B
B
bro-dev2016-02-08 21:11:42
JavaScript
bro-dev, 2016-02-08 21:11:42

How to move the input cursor to the beginning of the line on focus?

function moveCaretToStart(inputObject)
{
  if (inputObject.createTextRange)
  {
   var r = inputObject.createTextRange();
   r.collapse(true);
   r.select();
  }
}
$('.bro-form-phone').focus(function() {
    moveCaretToStart(document.getElementById("mytextbox"));
  });

I do this and don't know why it doesn't work. The problem is that if there is an input mask in the field, then when you click on the field, the cursor becomes somewhere in the middle, if you do not fill in all the symbols of the mask, then everything is erased.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bro-dev, 2016-02-08
@xPomaHx

All figured out, you need to use this plugin github.com/RobinHerbots/jquery.inputmask
and not this one
https://github.com/igorescobar/jQuery-Mask-Plugin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question