472,131 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,131 software developers and data experts.

Getting scrollbar line position from textarea?

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.

Jul 24 '06 #1
2 11359
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.
Jul 25 '06 #2
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.
Jul 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Johnny Two Dogs | last post: by
6 posts views Thread by Colin McGuire | last post: by
2 posts views Thread by musicmouse | last post: by
5 posts views Thread by reon | last post: by
reply views Thread by =?Utf-8?B?cGF0cmlja2RyZA==?= | last post: by
reply views Thread by leo001 | last post: by

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.