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

Looking for Word or character counting

excelgeek
Registered: Nov 3 2007
Posts: 44
Answered

Hello everyone
I am looking for a script that will count the characters and/or words in a textfield. Like you see in html forms online. One field for typing that multiline field and one field for live counting of characters or words. Anyone got an example?

My Product Information:
Acrobat Pro 8.1.7, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
For word count use split():
this.getField("Text1").value.split(" ").length
For character count just look at the length property:
this.getField("Text1").value.length

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

excelgeek
Registered: Nov 3 2007
Posts: 44
Thank you for your quick reply. I tried both scripts but neither returns a value. I placed in the calculating field under the custom calculation script. Any idea of why it didn't work?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I assume you're placing them on a different field, not the one where the text is inputted, right?
Also, you should adjust the name of the field to match the one in your file.
And, add this to the begining, as to assign the value to the field:

event.value =

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

excelgeek
Registered: Nov 3 2007
Posts: 44
Sorry guess I should have been more specific. I just noticed that I simply had an extra space which was not making the word count work correct but the character count still is not working. Suggestion?


event.value = this.getField("Text23").value.length

placed it in the custom calc script under Calculate. Thank you again for your assistance. Please reply with your company information so if I have more complex scripting that I can purchase your services.
excelgeek
Registered: Nov 3 2007
Posts: 44
Nevermind... figured it out kind of.. interesting..

If I type 12345679

It will not report 9 character but if I type

1234 5678

It reports 9 characters.. I requires at least one space for it to work.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
To solve that change .value to .valueAsString

If you want my scripting services you can contact me via email (click the link on the left), or through my website (the address should appear in my signature).

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com