Skip to main content
Graphic Squirrel
Inspiring
February 20, 2023
Question

How to determine the number of characters allowed in a text box?

  • February 20, 2023
  • 3 replies
  • 6030 views

Hello.  Been working in adobe apps for years, but fillable forms are fairly new to me.  I am creating a set of forms that have variable-sized fillable text boxes on each page.  For instance, one page may require a short statement (ie, went to the park), while the next page would require a long description of that first answer (ie, paragraphs describing how they went to the park and what they did while they were there).  Each text box must have a predetermined number of characters since the forms will be printed after they are completed.  I have searched but cannot figure out how to (1) let the user know how many characters are allowed in the text box before they start typing and (2) perhaps offer a little note that lets them know how many characters they have left in the text box as they are typing.  

Can anyone point me in the right direction to learn more about how to do this?  I just can't seem to find the answers.  

Thanks,

GS

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
February 21, 2023

The OP should obviously use a fixed-width font for this field, as Courier.

Acrobate du PDF, InDesigner et Photoshopographe
Legend
February 20, 2023

This is, it seems to me, going to be variable. Almost all fonts use a mixture of different widths. So a full box could be "siiiiiiiiiix" or "mmmmm". There are no features to tell you how much space is used by the current characters in the selected box, nor whether another character would fit.

try67
Community Expert
Community Expert
February 20, 2023

Is the number of allowed characters small, up to 10, say? If so, I would use the Comb option, as it both limits the number of characters allowed in the field, and provides a visual representation of the place for each one, like this:

 

If it's a larger number then the Comb option will not look very well. In that case you would need to use a script to do both tasks, and put the information in another text field, located next to the one the user edits.

Graphic Squirrel
Inspiring
February 20, 2023

Thanks for the reply.  All of the answers will be variable, so I don't think the comb will work.  One text box might hold 20 characters while the other is the entire page.  I'm just not sure how to determine the number of characters that would fit in the box (there must be some easy method other than literally typing characters and counting them).  And I'd like to have the little note that says "50 of 100 characters used..." so they will know how many characters they have left so they don't get to the end and have to go back and edit their text.  

try67
Community Expert
Community Expert
February 20, 2023

> there must be some easy method other than literally typing characters and counting them

There isn't really. And even doing it like that is tricky, because the width of each character is different, so you have to take that into consideration.

As for displaying the value in another field, you can do it using this code (as the custom Keystroke script of the first field, assuming the second one is named "Text2"):

 

this.getField("Text2").value = AFMergeChange(event).length + "/" + event.target.charLimit;

 

After you apply the code it will probably "disappear" and the Format setting will return to None, but it should still work. This is an annoying bug of Acrobat. If you want you can place the code in a doc-level function, so it can be used from multiple fields. You will then need to provide the name of the second field as a parameter, or use a consistent naming scheme to access it without specifying the actual name.