These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How can I show a running character counter on fields with character limits?

CecileL
Registered: Feb 23 2011
Posts: 3
Answered

I have several fields with character limits (example: "Organizational Profile, max. 1000 characters")
 
I would like form users to be able to see a running count either of the characters they've entered, or of the remaining characters in their limit, while they are typing.
 
Complicating factor: I do not speak script. However, I'm bright enough to cut and paste script if a) I'm told EXACTLY where to paste it (as in: "make sure 'javascript' is selected as the language, and 'client' is selected for run at; then in the 'show' box, select 'enter,' then paste this script AFTER the line of text that already shows in the script window"); and b) I'm told which items of the script are variables related to my form/field, and how to customize them for this function (as in: "where it says 'fn=fieldname' you need to replace 'fieldname' with the actual name you are using for the field, like orgprofile.")
 
If this requires me to add another field to actually show the running count, I'm fine with that, but I'll need instructions on how to link the two effectively.
 
Any help is MUCH appreciated!
 
(By the way, LiveCycle designers at Adobe, this would be a great addition for the next version of the program...)

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
Place this code in the change event for the field where you want the characters counted

MyCount.rawValue = xfa.event.fullText.length;

Where "MyCount" is the name of the field where the character count will be displayed.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

CecileL
Registered: Feb 23 2011
Posts: 3
I must be doing something wrong. The field where text is being entered is named "profile." Because I need it to expand, it must occupy an entire row of a table. So here's what I did:

1. Added another row to the table below "profile"
2. Inserted a text field into the row and named it "optextct"
3. Went back to "profile" and selected Javascript, run at client, and selected "change" from the "Show" list (there was not an option labeled "change event")
4. Cut and pasted the script in your post, and then replaced "MyCount" with "optextct"
5. Clicked on "Preview PDF" and entered some text into "profile."

"optextct" showed as a field, but nothing appeared in it as I was entering text. Do I need to set values for field "optextct" to enable the script to dump into it?

Sorry I'm such a noob at this, and I really appreciate the help!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The two things that are most likely to be problems.

1. The code is JavaScript, so the language pulldown on the scripting window needs to be set to JavaScript.
2. The SOM path to the "optextct" field is not properly specified. Since you mentioned that it exists in another row than the field being counted, I think this is very likely. The code I wrote was for two fields at the same hierarchy level in the form.

Watch this video:
http://adobechats.adobe.acrobat.com/p87746471/

It discusses how to use the hierarchy window and build a relative SOM path.

Also, look in the console window to see what's reported.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

CecileL
Registered: Feb 23 2011
Posts: 3
For future reference, here is how your additional assistance helped me solve the problem. The key was your reference to "the SOM path" and the video tutorial starting at about 8:20. Once I figured out that the problem was that I hadn't adequately pointed the script to the destination object, I went back to livecycle and used the handy-dandy context-sensitive instructions that are RIGHT THERE about getting the correct SOM path inserted, to wit:

"To insert an object's SOM into the editor, press CTRL (relative-SOM) or CTRL+SHIFT (absolute-SOM) and click on an object."

Well, paint me purple and call me a grape. That seems to have done the trick.

Profound and reverent thanks for the script, and for the cool video tutorial which, while it is unlikely to turn me into a savvy scripter, will certainly help me understand more about what is happening and why!

Cecile