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

Inserting a comma and whitespace

Participant ,
Mar 13, 2018 Mar 13, 2018

So I've been working at this for awhile.  The situation is that users complete a form inputting their Last name, First name MI.  The problem is they're supposed to include the comma between the Last name and First name but sometimes they don't.  I tested the code below in W3Schools.com "Tryit Editor", and it works fine.  It just doesn't in my PDF file.  Here is what I have so far:

function fComma() {

    var str = this.getField("01: Name").value;

    var res = str.replace(/,|\s+/, ',\n')

    this.getField("01: Name").value = res;

}

And I also don't know where to place the function.  I currently have the function at document level and tried calling it from the Actions tab, the Format tab in Custom Format Script, and I tried it in the Custom Validation Script tab.  None of them are working so I'm betting the script is messed up.

Please help.

TOPICS
Acrobat SDK and JavaScript , Windows
530
Translate
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
Community Expert ,
Mar 13, 2018 Mar 13, 2018

The Validate or Custom Keystroke script will work, but you have to access the field values correctly. At the time of validation the field value is not yet set, so using getField gets the previous value.

replace "this.getField" with "event.value";

also set

event.rc = true;

The validation script validates the user entry. It's important to set the return code to true so Acrobat knows not to invalidate the value.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
Participant ,
Mar 13, 2018 Mar 13, 2018
LATEST

Thom,

That worked, thank you.

Translate
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