• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Character Counting w/o spaces

New Here ,
Feb 03, 2019 Feb 03, 2019

Copy link to clipboard

Copied

Hello folks,

To start, rest assured I am not a student looking for answers on homework. Rather I am a graphic designer who stepped out of his box a bit too far and need help. I am wanting to have a textbox (Text1) for entering info and a separate textbox (Text2) display only the numbers of characters used [without spaces]. I don't even need the msg part either, just a number that is counting as the customer types. We are charging by the actual character for this form and not the spaces. Below is the only code I have found to function in my document, however it is beyond me on how to adjust it to my needs. Please help and thank you!

THIS ONE WORKS:

(Drop into ‘Custom Keystroke Script’)

Javascript below is for a character cnt w/spaces and a message of remainder.

if (event.willCommit == false) {

    var ec = event.change;

    var nv = event.value + ec;

    var nc = nv.length;

    var msg = nc + " characters typed.\n";

    msg += (3000 - nc) + " remaining.";

   this.getField("counter").value = msg;

}

TOPICS
Acrobat SDK and JavaScript

Views

199

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 03, 2019 Feb 03, 2019

Enter this code as the custom Keystroke event of the text field:

this.getField("counter").value = AFMergeChange(event).replace(/\s/g, "").length;

It's possible that when you press OK after entering it it will disappear and the selection will revert to None, but it's actually there, so just click Close, save the file, and it should work.

Likes

Translate

Translate
Community Expert ,
Feb 03, 2019 Feb 03, 2019

Copy link to clipboard

Copied

Enter this code as the custom Keystroke event of the text field:

this.getField("counter").value = AFMergeChange(event).replace(/\s/g, "").length;

It's possible that when you press OK after entering it it will disappear and the selection will revert to None, but it's actually there, so just click Close, save the file, and it should work.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 04, 2019 Feb 04, 2019

Copy link to clipboard

Copied

LATEST

Very awesome! Thank you for the quick response!!!!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines