java script to show last lines of textarea

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • modelpatel
    New Member
    • Dec 2007
    • 5

    java script to show last lines of textarea

    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,

    Bharat
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    have a look at the following example:

    [CODE=javascript]var n = document.getEle mentById('your_ message_text_ar ea_id');
    var end = n.lastChild.off setTop;
    window.scrollTo (0, end);[/CODE]
    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

    Comment

    • srinivasanm
      New Member
      • Apr 2008
      • 1

      #3
      HI,

      I hope below things will work for you.

      [CODE=javascript]obj = document.getEle mentById(divid) ;
      var currentScrollHe ight = obj.scrollHeigh t;
      obj.scrollTop = (obj.scrollTop + 100000); //set the scroll height to scroll by here.[/CODE]

      srini
      Last edited by gits; Apr 3 '08, 09:09 AM. Reason: added code tags

      Comment

      Working...