# Text\_area scroll to bottom

**URL:** <https://www.ruby-forum.com/t/text-area-scroll-to-bottom/165475>\
**Category:** Rails\
**Created:** [April 14, 2009, 11:23am UTC](https://www.ruby-forum.com/t/text-area-scroll-to-bottom/165475 "2009-04-14T11:23:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [April 14, 2009, 11:23am UTC](https://www.ruby-forum.com/t/text-area-scroll-to-bottom/165475/1 "2009-04-14T11:23:54Z")

</div>

Hi,

I have a text\_area that fills in the text from a controller and I am  
using RJS to update the text area content. I want to set the scroll bar  
to bottom so that the user need not scroll to bottom to get the updated  
value, how do I do that I tried

page[“status”].scrollTop = page[“status”].scrollHeight

This somehow does not work in the RJS

Thanks,  
Sudhi

---

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [April 14, 2009, 9:40pm UTC](https://www.ruby-forum.com/t/text-area-scroll-to-bottom/165475/2 "2009-04-14T21:40:33Z")

</div>

Sudhi K. wrote:

> I have a text\_area that fills in the text from a controller and I am  
> using RJS to update the text area content. I want to set the scroll bar  
> to bottom so that the user need not scroll to bottom to get the updated  
> value, how do I do that I tried
> 
> page[“status”].scrollTop = page[“status”].scrollHeight

Event.observe(window, “load”, function() {  
$(‘input\_area’).scrollTop = $(‘input\_area’).scrollHeight;  
});

This worked in my quick test in Safari 4.0 beta and Firefox 3.0.8, so it  
looks like the the JavaScript part of what you’re doing is fine. My  
guess is that you might have a timing issue of some sort. Notice that  
the above code waits for the page to fully load before scrolling the  
text area for example.

---

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [April 15, 2009, 5:17am UTC](https://www.ruby-forum.com/t/text-area-scroll-to-bottom/165475/3 "2009-04-15T05:17:08Z")

</div>

Robert W. wrote:

> Sudhi K. wrote:
> 
> > I have a text\_area that fills in the text from a controller and I am  
> > using RJS to update the text area content. I want to set the scroll bar  
> > to bottom so that the user need not scroll to bottom to get the updated  
> > value, how do I do that I tried
> > 
> > page[“status”].scrollTop = page[“status”].scrollHeight
> 
> Event.observe(window, “load”, function() {  
> $(‘input\_area’).scrollTop = $(‘input\_area’).scrollHeight;  
> });
> 
> This worked in my quick test in Safari 4.0 beta and Firefox 3.0.8, so it  
> looks like the the JavaScript part of what you’re doing is fine. My  
> guess is that you might have a timing issue of some sort. Notice that  
> the above code waits for the page to fully load before scrolling the  
> text area for example.

Hi,  
Thanks for the input…

The problem I see is that the textarea content is filled later on and  
not onload. Does this update the scrollbar position even after the  
textarea content is updated?

Thanks,  
Sudhi
