A variation on the textbox length-checking dilemma

A

AsZe

Hi :)

I really did try to keep this short but I'm notoriously bad at writing
anything short, so...

Okay, so the situation is as follows: there's a page with a list of
textboxes (varying amount of them), and we want to control the length
of the text that goes into each of them (the textboxes all have the
same max size of content). I know, I know, it's been done in 50-
zillion ways already. But, our version has a twist!

You see, the data from these textboxes then fills some fields in PDF
forms. These fields are kinda like divs with a specific width and
height set - and we want to make sure that anything accepted by the
form will look good on the PDF form, that is, fit in those fields.

For the sake of the explanation, let's imagine we have a PDF field
that accepts 3 rows of text by 60 columns.

Consider the following text:
Lorem ipsum dolor sit amet. Consectetuer adipiscing elit,
maecenas ac magna a dolor iaculis pretium. Pellentesque
interdum. Nunc ut arcu. Proin porta feugiat urna.
This is roughly 162 characters, all in one long line that wraps into 3
lines. It'll be accepted by most any JavaScript textbox-length-
checker, and rightly so, since it'll look okay on the finished PDF.

Now, consider this text:
Lorem ipsum dolor sit amet.
Consectetuer adipiscing elit, maecenas ac magna a dolor
iaculis pretium.
Pellentesque interdum. Nunc ut arcu.
Proin porta feugiat urna.
This is the exact same text - so still 162 characters - but there's 3
newlines in it, which makes the text span 5 lines in all. We don't
want to accept this one, since it'll mess up the whole PDF form.

I know how I could write the code in PHP, but that's useless since I
want it to check the length _before_ the form content is submitted.
The problem is my knowledge of JavaScript is pretty much nonexistent -
I can change variables and stuff, but overall, I'm total rubbish at
it. Hence why I'm asking for help here.

Thanks in advance,

Alicja Z.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
What you are going to have to do is reformat the text so that instead
of soft-wrapping you cause it to hard wrap. Then count the lines.

The OP can find such a reformatter in function Pak_ of
<URL:http://www.merlyn.demon.co.uk/js-quick.htm>.

That recognises paragraphing, which the OP does not IIRC call for; but
if the OP wishes to preserve existing hard returns then the paragraph
handling needs to be changed to hard return handling.

If the OP had wished to deal with text by retaining all hard returns
without adding any wrapping, then a RegExp check would suffice.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
T

Thomas 'PointedEars' Lahn

AsZe said:
You see, the data from these textboxes then fills some fields in PDF
forms. These fields are kinda like divs with a specific width and
height set - and we want to make sure that anything accepted by the
form will look good on the PDF form, that is, fit in those fields.

The aforementioned fact aside that counting characters alone will not help,
I don't think this can be done in general. PDF provides fully scalable
display and allows to specify and embed the font that is to be used; HTML,
by default, does not.


PointedEars
 

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
474,147
Messages
2,570,835
Members
47,382
Latest member
MichaleStr

Latest Threads

Top