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

java script to show last lines of textarea

P: 5
Hi every one,

I have a question regarding the lastline in Textarea. I am have build a chat application using the textarea to display the typed messages. Every thing is working fine except once the text range is out of the textarea size I have to scroll down to check for the new messages. Can anyone help me to display the last lines of in textarea always using javascript.

Thanks & Regards,

Feb 2 '08 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 5,327
hi ...

have a look at the following example:

Expand|Select|Wrap|Line Numbers
  1. var n   = document.getElementById('your_message_text_area_id');
  2. var end = n.lastChild.offsetTop;
  3. window.scrollTo(0, end);
so we refer to the div where you output the messages, and then we refer to its last added child ... and then we scroll to its top position ... note: i assume that it is a div where you assign the messages to? typically you have an input area (to type in) below or before an readonly messages-output 'window' (where the recent messages appear)?

kind regards
Feb 4 '08 #2

P: 1

I hope below things will work for you.

Expand|Select|Wrap|Line Numbers
  1. obj = document.getElementById(divid);
  2.         var currentScrollHeight = obj.scrollHeight;
  3.         obj.scrollTop = (obj.scrollTop + 100000); //set the scroll height to scroll by here.
Apr 3 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.