Getting scrollbar line position from textarea?

Discussion in 'Javascript' started by Mike Brophy, Jul 25, 2006.

  1. Mike Brophy

    Mike Brophy Guest

    Here's my problem: I need to present text in a scrolling textarea such
    that a checkbox is not enabled until the user has scrolled to the very
    last line of the text using the vertical scrollbar.

    Been searching for some functions to get scrollbar position for a
    textarea object but coming up empty.

    A nudge in the right direction would be appreciated. Thanks.
    Mike Brophy, Jul 25, 2006
    #1
    1. Advertising

  2. Mike Brophy

    JustinBlat Guest

    I would check out the scrollTop and scrollHeight properties of the
    textarea control. The scrollTop will tell you how far down the control
    is scrolled, and the scrollHeight tells you the total scrollable length
    - I think you would want to handle the onscroll property, and ensure
    these values are even.

    *** completely untested code snippet ***
    <script language="JavaScript">
    function myTextArea_OnScroll(myTextArea) {
    if (myTextArea.scrollTop == myTextArea.scrollHeight) {
    document.getElementById('myCheckBox').disabled = false;
    }// end if
    } // end myTextArea_OnScroll function
    </script>
    <textarea onscroll="myTextArea_OnScroll(this);"></textarea>
    <input type="checkbox" id="myCheckBox" disabled>

    Happy Coding!


    Mike Brophy wrote:
    > Here's my problem: I need to present text in a scrolling textarea such
    > that a checkbox is not enabled until the user has scrolled to the very
    > last line of the text using the vertical scrollbar.
    >
    > Been searching for some functions to get scrollbar position for a
    > textarea object but coming up empty.
    >
    > A nudge in the right direction would be appreciated. Thanks.
    JustinBlat, Jul 25, 2006
    #2
    1. Advertising

  3. Mike Brophy

    Mike Brophy Guest

    The scrollTop/onScroll solution is a good one for IE and your code
    snippet was much appreciated, however the onscroll event for
    Mozilla/Firefox isn't working (it has been filed as a bug:
    https://bugzilla.mozilla.org/show_bug.cgi?id=229089).

    Upon further research I'm going to use a scrolling DIV layer to display
    the text and put a checkbox at the bottom, serving the same purpose
    that a user won't see the checkbox unless they have scrolled to the
    last line of the DIV layer.

    Thanks for your help!

    Mike


    JustinBlat wrote:
    > I would check out the scrollTop and scrollHeight properties of the
    > textarea control. The scrollTop will tell you how far down the control
    > is scrolled, and the scrollHeight tells you the total scrollable length
    > - I think you would want to handle the onscroll property, and ensure
    > these values are even.
    >
    > *** completely untested code snippet ***
    > <script language="JavaScript">
    > function myTextArea_OnScroll(myTextArea) {
    > if (myTextArea.scrollTop == myTextArea.scrollHeight) {
    > document.getElementById('myCheckBox').disabled = false;
    > }// end if
    > } // end myTextArea_OnScroll function
    > </script>
    > <textarea onscroll="myTextArea_OnScroll(this);"></textarea>
    > <input type="checkbox" id="myCheckBox" disabled>
    >
    > Happy Coding!
    >
    >
    > Mike Brophy wrote:
    > > Here's my problem: I need to present text in a scrolling textarea such
    > > that a checkbox is not enabled until the user has scrolled to the very
    > > last line of the text using the vertical scrollbar.
    > >
    > > Been searching for some functions to get scrollbar position for a
    > > textarea object but coming up empty.
    > >
    > > A nudge in the right direction would be appreciated. Thanks.
    Mike Brophy, Jul 25, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pvonk
    Replies:
    1
    Views:
    641
    Michael Dunn
    Sep 8, 2005
  2. =?Utf-8?B?cGF0cmlja2RyZA==?=

    1) textarea firefox scrollbar 2) input check border 3) datagrid si

    =?Utf-8?B?cGF0cmlja2RyZA==?=, May 14, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    435
    =?Utf-8?B?cGF0cmlja2RyZA==?=
    May 14, 2007
  3. Nick
    Replies:
    1
    Views:
    365
    Fernando Rodriguez
    May 1, 2008
  4. Nick
    Replies:
    0
    Views:
    344
  5. Alex

    ScrollBar? Does it exist just WEB ScrollBar Control?

    Alex, Apr 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    259
    Alvin Bruney [MVP]
    Apr 4, 2004
Loading...

Share This Page