2

Lot's of solutions here on stackoverflow show how to focus the cursor at the end of an input text but they don't show how to focus visually the end of a input text - the overflow of an input text.

Ex:

Most of the solutions are focus at the end but show the start of the text:

enter image description here

enter image description here

But via javascript, I want to focus the end:

enter image description here

Edit:

Not duplicate because

dir="rtl"

doesn't solve it. I want to fill the field left to write, but when click on it I want to scroll to the end of the input text. @ibiza's answer solved the problem.

armoucar
  • 408
  • 1
  • 4
  • 15
  • See here: http://help.dottoro.com/ljtfkhio.php – Pluto Mar 25 '15 at 17:28
  • possible duplicate of ["Scroll" to the very right of a long text input](http://stackoverflow.com/questions/1962168/scroll-to-the-very-right-of-a-long-text-input) – Sergiu Paraschiv Mar 25 '15 at 17:28
  • yes, possible duplicate, **and** the answer here from ibiza is an exact copy of [Lucman Abdulrachman](http://stackoverflow.com/users/2031863/lucman-abdulrachman)'s answer on that other question. – Stephen P Mar 25 '15 at 17:35
  • @StephenP yeah, that's true. should I delete my question? That solves. – armoucar Mar 25 '15 at 17:38

2 Answers2

4
$('#myInput').get(0).scrollLeft = $('#myInput').get(0).scrollWidth; 
Bruno
  • 4,685
  • 7
  • 54
  • 105
0

Use the code below

<input type="text" id="search" value="Some People like cupcake better" />
<script>
document.getElementById("search").scrollLeft = document.getElementById("search").scrollWidth; 
</script>

DEMO: LINK

Hope this helps you

Utkarsh Dixit
  • 4,267
  • 3
  • 15
  • 38