473,473 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

textarea/.net textbox scroll to end

Hi,
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.

Rob
Jul 23 '05 #1
1 7272


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">
<head>
<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;
}
</script>
</head>
<body>
<form action="" onsubmit="return false;" name="formName">
<p>
<textarea name="textareaName" rows="10" cols="80"></textarea>
</p>
<p>
<input type="button" value="random fill, scroll to end"
onclick="randomFill(this.form.textareaName);
scrollElementToEnd(this.form.textareaName);">
</p>
</form>
</body>
</html>

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
http://JavaScript.FAQTs.com/

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stefano Incontri | last post by:
Hi All, how can I scroll a TextArea to its last position at the bottom? Thanks, Stefano
5
by: Richard | last post by:
I am filling a TEXTAREA with text and links from a database. I need to display the <a href....> code in the TEXTAREA as a clickable link with _blank targetting. I realise I could simply use a TD...
6
by: stuart | last post by:
I have two textareas on a HTML page. If a user scrolls in one textarea I want the other textarea to scroll as well. In otherwords I want both textareas to scroll up and down in unison. Can...
9
by: Paul Gorodyansky | last post by:
Hi, FAQ tells how to insert (or replace0 a text at a caret position in Mozilla (and same works for Opera 8+), for example, at http://www.faqts.com/knowledge_base/view.phtml/aid/1661 it talks...
1
by: Samir Patel | last post by:
Hi I am using Textarea type.I want to set maximum length to the textarea. I am using following code for the same,but it is not working, <textarea name="txtDescription" cols=10 rows=3...
2
by: musicmouse | last post by:
Happy new year to you all, I have a problem with the css settings for the horizontal scrollbar of a textarea. When I look at my textarea's in Internet Explorer (I use 5.5) I see only a...
4
by: Keith Bentrup | last post by:
Hi all, I wrote a simple search function to find text in a textarea where not all the text is visible (ie. the text box displays 10 lines but there may be more than 1000 lines to search). I can...
2
luke14free
by: luke14free | last post by:
Hello, I'm writing a live chat in php and ajax (prototype.js). My problem is that, when the periodical updater gets chat text from an external php page, under IE \n\r are not recognized ...
1
by: RFleming | last post by:
I attempted to use the advice below, but still I keep getting word wrap in my inputtextarea. I am very new to XML and CSS, and I do not totally understand the layout. Below is the single XML line...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.