Forum: Ruby on Rails Text_area scroll to bottom

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-04-14 11:23
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
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2009-04-14 21:40
Sudhi Kulkarni 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.
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-04-15 05:17
Robert Walker wrote:
> Sudhi Kulkarni 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
This topic is locked and can not be replied to.