View Full Version : Scroll to bottom of a textarea (Using Javascript + Safari)

Dec 12, 2006, 08:40 AM
I am actually attempting to develop a widget, where I am using a console for users to enter text, and receive a response. I am using a TEXTAREA HTML object for the main console, but I am having trouble with the scrolling. In most browsers, you can force the scroll position to the end of the textarea with this code:

textareaelem = document.getElementById('mytextarea');
textareaelem.scrollTop = textareaelem.scrollHeight;

but this doesn't work in Safari or dashboard. I don't get any javacsript errors or warnings, either. Interestingly, it does appear to work with WebKit.

Developing a widget has so far been a VERY frustrating experience, and I have found that Safari's support for javascript leaves much to be desired, and can be very quirky, especially compared to Firefox.

Dec 13, 2006, 01:53 PM

Dec 13, 2006, 03:17 PM
Have you tried seeing what the values of textareaelem.scrollTop and textareaelem.scrollHeight actually are?

Or try using a fixed number to see what the behavior might be.

textareaelem.scrollTop = 200;

Also, I know you don't have to but have you tried playing with the overflow CSS attribute for that textarea?

Dec 14, 2006, 09:05 AM
I have tried some CSS modifications, currently I have this:
overflow-y: scroll;

any other CSS attributes i may need to set?

i will have to look more into what the values of those scroll variables are. is there anything I can send to re-draw the textarea? Like perhaps the scroll values are being updated fine, but just not triggering an update to redraw the control?

Dec 14, 2006, 09:45 PM
As I enter text and scroll around the textarea manually, scrollTop always remains at 0 and never changes. The scrollHeight also stays constant at 200px, which is the initial height of the textarea, and never changes. Even if I attempt to change the value of scrollTop by setting equal to some constant number, it never changes. This works in every other browser but safari.

Any other help or input would be very much appreciated!!

Dec 18, 2006, 09:14 AM
It appears that Safari does not support javascript for scrolling textarea objects, only div objects.

so here is plan B:
create a fake keyboard event and process it, specifically a "END" keydown event which should scroll to the end of the textarea. Anyone know how to create a keydown event object and process it?