Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I scroll HTML textbox to the end?

If the content of a HTML textbox is longer than the textbox width, part of it is hidden and you need to scroll the textbox to see the end. Is there anyway to scroll it in JS or CSS to the end?

like image 624
Bill Software Engineer Avatar asked Dec 16 '22 03:12

Bill Software Engineer


1 Answers

Width

Here's for an <input type="text" /> and width.

var ta = document.getElementById('temp');
ta.scrollLeft = ta.scrollWidth;

And my fiddle is updated to show this.

Here's my previous response with doing it for the height.

Height

You can use scrollHeight and scrollTop on an element to do this.

var ta = document.getElementById('temp');
ta.scrollTop = ta.scrollHeight;

Fiddle: http://jsfiddle.net/derekaug/JGqtA/

like image 112
derekaug Avatar answered Dec 30 '22 04:12

derekaug