How to fix cursor movement when editing and validating an input?

  • 0
    Hello!
    Input.value is separated by a space every 3 characters.
    How do I keep the cursor in place while editing?
    Now goes to the end of the line

    JavaScript Anonymous, May 4, 2019

  • 1 Answers
  • 0
    When the change starts, keep the caret position input.selectionStart

    After replacing the value in the input - set the carriage position
    input.setSelectionRange(startPos,endPos) // Обе позиции должны быть одинаковыми, например (1,1)
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!