Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Getting scrollbar line position from textarea?

Reply
Thread Tools

Getting scrollbar line position from textarea?

 
 
Mike Brophy
Guest
Posts: n/a
 
      07-24-2006
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.

 
Reply With Quote
 
 
 
 
JustinBlat
Guest
Posts: n/a
 
      07-25-2006
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.


 
Reply With Quote
 
 
 
 
Mike Brophy
Guest
Posts: n/a
 
      07-25-2006
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to keep position of scrollbar Green ASP .Net 2 07-17-2004 03:36 PM
how to remember asp:listbox's scrollbar position Daniel ASP .Net 1 07-16-2004 02:10 AM
ScrollBar? Does it exist just WEB ScrollBar Control? Alex ASP .Net Web Controls 1 04-04-2004 12:44 AM
How to clear the scrollbar position programatically, take 2 Carl Mercier ASP .Net 1 03-02-2004 06:25 AM
Re: how datagrid scrollbar can keep same position after postback Steve C. Orr, MCSD ASP .Net 0 08-01-2003 06:58 PM



Advertisments