Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thom,
That worked, thank you.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now