Answered
The following code works perfectly in Acrobat 8 Professional but is giving me issues in Acrobat 9 Reader. When I run it in 9 Reader, the alert window does not close when I click OK or press Enter . The only way I can get it to close is by holding down Enter. The code is set to run a javascript when the OnBlur action occurs.
Any idea why this is happening?
f = getField(event.target.name);
if (f.value.length == 0) {
f.setFocus();
app.alert("This field is required. Please enter number.");
}
In Acrobat 8 the timing is a bit different so that the focus is set back to the field after the alert returns. And that of course is the solution, move the setFocus() after the alert.
There are a couple of other things that are not quite right with this script. First, the getField line is redundant. The field is already in the event object, i.e, event.target. The script should look like this.
Second, the script itself, while it works, falls a ways outside of best practices. Field validation should be done in two places, in the Validate event and at submission time.
Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]
The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script