0

I have a bunch of textfields which identical starting data, the first 2 dozen characters are all the same for every input.

The end is different.

How do I get the textfield to scroll right automatically to show the end by default?

Harry
  • 52,711
  • 71
  • 177
  • 261

2 Answers2

0

You can try with the scrollTo javascript function:

var myTextfield = document.getElementById("myTextfield");
myTextfield.scrollTop = myTextfield.scrollHeight;
Johan Olsson
  • 608
  • 3
  • 10
  • There's no height. Just width – Harry May 23 '11 at 08:12
  • the scrollHeight is not the containers height, its just the measurement of how much height you are able to show by scrolling. and besides i think that all textfealds have a default height. – Johan Olsson May 23 '11 at 08:18
0

@el toni has a great solution. However, the textfield won't function properly if the user is required to input any text. (The cursor will jump to the left.)

<input dir="rtl" value="https://stackoverflow.com/questions/1962168/scroll-to-the-very-right-of-a-long-text-input">

(*Above from "Scroll" to the very right of a long text input courtesy @el toni)

You could use some js so that when the user clicks on the field, the "right direction" for text input is re-established. Then change it back to the other direction after he/she clicks off.

 $("#longInput").focus(function () {
     $(this).attr('dir', 'ltr');
});
 $("#longInput").blur(function () {
     $(this).attr('dir', 'rtl');
});

http://jsfiddle.net/kjjL2/

Community
  • 1
  • 1
Jason Gennaro
  • 34,535
  • 8
  • 65
  • 86