By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

textarea/.net textbox scroll to end

P: n/a
is there a way using JavaScript to tell a textarea to scroll to the end of
it's contents? I'm implementing something that looks like messenger using
web forms, after each post the chat area gets updated but I have to manually
scroll it down to the end.

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a

Rob Webster wrote:

is there a way using JavaScript to tell a textarea to scroll to the end of
it's contents?

With some browsers (tested successfully with IE 6, Netscape 7.1, Mozilla
1.7, should work with IE 5/5.5, Netscape 7.0, Mozilla 1.x too) the
following works

<html lang="en">
<title>scrolling a textarea to its end</title>
<script type="text/javascript">
function scrollElementToEnd (element) {
if (typeof element.scrollTop != 'undefined' &&
typeof element.scrollHeight != 'undefined') {
element.scrollTop = element.scrollHeight;

function randomFill (textarea) {
var numberOfLines = Math.floor(Math.random() * 20) + 10;
var text = '';
for (var i = 1; i <= numberOfLines; i++) {
text += 'Line ' + i + '\r\n';
textarea.value = text;
<form action="" onsubmit="return false;" name="formName">
<textarea name="textareaName" rows="10" cols="80"></textarea>
<input type="button" value="random fill, scroll to end"

Opera 7.50 doesn't scroll the textarea however although it seems to
support scrollTop and scrollHeight, I am not sure what the problem is
without looking into it further.
Netscape 4 doesn't support that.


Martin Honnen

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.