By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

A variation on the textbox length-checking dilemma

P: n/a
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.
Nov 21 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In comp.lang.javascript message <Qq*********************@giganews.com>,
Wed, 21 Nov 2007 18:22:24, Randy Webb <Hi************@aol.composted:
>
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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 22 '07 #2

P: n/a
AsZe wrote:
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
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Nov 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.