Newbie Question: How do I know how many rows of text will appear in atext area?

T

Tojuso

I have a text area that I need to scroll one page at a time until the
end of the document. I have a problem, however. How do I know how
many pages to scroll before I hit the end of the document? HTML will
presumably take care of all the word-wrapping, so it is difficult - if
not impossible - for me to determine the number of rows beforehand.
As far as I can tell, there is no direct way to tell how many rows of
text will be generated by the browser except, perhaps, through use of
trial-and-error. But this is not practical because the text will
change from one day to the next, and I need to deploy this over a lot
of different text articles. So I need a general solution.

Any help and/or suggestion is appreciated! Thanks in advance.

-Dan
 
E

Evertjan.

Tojuso wrote on 20 nov 2007 in comp.lang.javascript:
I have a text area that I need to scroll one page at a time until the
end of the document. I have a problem, however. How do I know how
many pages to scroll before I hit the end of the document? HTML will
presumably take care of all the word-wrapping, so it is difficult - if
not impossible - for me to determine the number of rows beforehand.
As far as I can tell, there is no direct way to tell how many rows of
text will be generated by the browser except, perhaps, through use of
trial-and-error. But this is not practical because the text will
change from one day to the next, and I need to deploy this over a lot
of different text articles. So I need a general solution.

A textarea is for inputting text,
use a div for showing text.

Even so I have no ready answer to your Q.

You could mesure the hight of the momentarily non scrolling long div and
arithmetically compare, read divide, that with the hight of dynamically
changed to a scrollable and fixed height div?
 
T

Tojuso

Thanks for your replies.

I'm not sure where to render the text; either a div section or a
textarea will do, as long as they work. Basically, I'm trying to
scroll text from articles in a controlled sort of way, where the user
can adjust how fast the text scrolls and how long the page stops after
a new page has scrolled into view. (There will also be some
overlaying graphical effects.) What I thought would be a trivial
problem is actually turning out to be a lot more difficult. The
reason I started this thread in this newsgroup is that I was hoping
someone could tell me about a magic function that could calculate the
number of rendered lines, given the text and the font type. An added
benefit would be if it also returned an array of Strings where each
array element would be a line of rendered text. This would then allow
me to scroll through the text and know what each line looks like as
well as know when the scrolling has reached the bottom. (The
application is used for certain types of tests, where the client is
"timed" on the reading material.) I have done some Java programming
in the past, and I know there are routines that "kind of" give me this
magical function, but it is a very complex subject in Java, with lots
of unimplemented interfaces that I'd have to research and program.
Bah! I'm too lazy to spend a big chunk of my life trying to sort it
all out.

In the end, I think I'll take the advice from this forum and try to
force a fixed-width font and render into, say, a table with invisible
borders. I may not get a very sexy-looking scrolling function, but at
least I'll have some control over how the content is rendered. By
using tables, the user can force a proportional font, but he/she would
still be unable to force more text onto a rendered page.

I don't have a URL of a sample page ... it's still in the works.

Thanks again everyone for your replies!

-Dan
 
T

Tojuso

Tojuso said the following on 11/20/2007 4:10 PM:


Please quote what you are replying to. It makes it a lot easier to
follow the conversation without having to look up old threads to read
them. Not everybody posts from Google Groups.

Will do. Thanks!
I don't really have the motivation to write a complete script to do
this. It *is* a lot of work. What I will do is give you the basics and
you can start from there and see if you really want to do it or not. I
will also give you some of the pitfalls.

This page: <URL:http://members.aol.com/_ht_a/hikksnotathome/typingText.html>
I took a brief look at the code, and indeed, it is a bit complicated,
but it seems to work on the demo page quite well, so maybe it's worth
a shot.

There's a function in Java that allows you to pre-format text for
wrapping, but of course, Java has the luxury of drawing on the screen
without browser "cooperation".

I'll keep working on this solution in Javascript.

My first instinct wsa that this indeed was going to be a lot of work,
and this thread has convinced me that my first instinct was correct.
I can work on the solution now without fear of having someone come by
six months later and say something like, "Why didn't you just use
function xyz and do this all in one line?" It's difficult to maintain
composure after you spent many a night coding a function that you
didn't know already exists. I've been there too many times already.

Thanks again for your response!

-Dan
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top