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

Adding Character Count of Five fields while typing.

Greaser
Registered: Jun 1 2011
Posts: 4
Answered

Browsing and Searching the forum, I found this thread which has helped a little, but it's already answered, and I have a separate but relatable problem, here's the old thread:
 
http://acrobatusers.com/forum/javascript/adding-character-count-two-fields-while-typing
 
From that thread, I copy and pasted the code, and was quite successful in getting the character count from two fields, here is what I added to my form in acrobat, from the 3rd post in the above thread:
 
Code:
//put in Custom Keystroke Script of the two "Name" fields to be counted
if(!event.willCommit)
{
var oName = this.getField("Name2"); //the other field to count (change accordingly)
var nDisplay = this.getField("CharCnt"); //to display the result
var nChars = event.selEnd - event.selStart;
var aFull = event.value.split("");
aFull.splice(event.selStart, nChars, event.change);
var strFull = aFull.join("");
nDisplay.value = strFull.length + oName.value.length;
}
 
I changed the field names to match my document, however, I would like to get the character count of five fields and add them while typing to a separate field. Again, the above works great for just two fields, but I need five.
 
Thanks for your help!

My Product Information:
Acrobat Pro 9.4.3, Macintosh
Greaser
Registered: Jun 1 2011
Posts: 4
Maybe I should rephrase my question, might sound a little confusing... I just need to be able to take 5 form fields, and have that output a character count to one text area. Doesn't need to count backwards from the max or anything, just count up.

As the user types, the character count goes up. I can copy and paste the code if you have it, or tell me exactly what to add and where to the above.

THANKS!
hogwell
Registered: Apr 16 2011
Posts: 6
Accepted Answer
I haven't tried this, but it looks like you could extend this algorithm to 5 fields:

if(!event.willCommit)
{
var oName2 = this.getField("Name2"); //the other field to count (change accordingly)
var oName3 = this.getField("Name3"); //the other field to count (change accordingly)
var oName4 = this.getField("Name4"); //the other field to count (change accordingly)
var oName5 = this.getField("Name5"); //the other field to count (change accordingly)
var nDisplay = this.getField("CharCnt"); //to display the result
var nChars = event.selEnd - event.selStart;
var aFull = event.value.split("");
aFull.splice(event.selStart, nChars, event.change);
var strFull = aFull.join("");
nDisplay.value = strFull.length
+ oName2.value.length + oName3.value.length + oName4.value.length + oName5.value.length;
}

Greaser
Registered: Jun 1 2011
Posts: 4
HOLY MOLY this worked great! Thanks!