Getting scrollbar line position from textarea?

M

Mike Brophy

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.
 
J

JustinBlat

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!
 
M

Mike Brophy

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top