473,411 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

A variation on the textbox length-checking dilemma

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
2 1374
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Ramsin Savra | last post by:
Hi, What do you suggest to do if I want to do a search in TextBox ? I know that using RichTextBox, we could have Find method to search for a specific word or information but I was wonder if...
6
by: Stuart Ferguson | last post by:
Is there a way from a textbox that you can establish the maximum length of the text that will be displayed in the textbox on the screen. What i am not requring is the Max Length of the Textbox...
9
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control,...
2
by: Peter | last post by:
I hate using the mask edit conrol so I created these two function to format my phone numbers. Is there a way to consolidate these two functions into one? In this example say the textbox you...
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
8
by: nil | last post by:
Hello all, It's urgent... i want to add autocomplete textbox facility in my application like google. as you type it suggests option to the user..i want the same kind of facility...i know i...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
1
by: rakeshnair | last post by:
i wrote a code in jsp to create dynamic table..the problem is i need data base connection when cursor moves from one cell to other... eg...when i enter product id in the first cell, the product name...
2
by: mrutyunjaya | last post by:
hello, i have two textbox column and one button control in gridvie when i click button it will ask plese enter price in first textbox . when enter values it is asking again. how to pass...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.