I'm trying to write a javascript that will permit only a "E" or "M" in a text field.
How do I go about doing this? I'm using Adobe 8 Professional Acroform.
Thanks,
kdburley
My Product Information:
Acrobat Pro 8.1.2, Windows
I recently answered a similar question, so here's a modified version of that response:
What you want is a custom keystroke script. Since it will be used by several fields, you should create a document level JavaScript (Advanced > JavaScript > Document JavaScripts) and add the following code:function EorM_ks() {
// Convert input to uppercase event.change = event.change.toUpperCase();
// Get everything that the user has entered so far var value = AFMergeChange(event);
// Do nothing if there are no characters if(!value) return;
//If user attempts to enter anything other than E or M, reject it if(!AFExactMatch(/[E]|[M]{0,1}/, value)) event.rc = false; }
Now, as the custom keystroke script for each field that you want to do this for, use the following:
What you want is a custom keystroke script. Since it will be used by several fields, you should create a document level JavaScript (Advanced > JavaScript > Document JavaScripts) and add the following code:function EorM_ks() {
// Convert input to uppercase
event.change = event.change.toUpperCase();
// Get everything that the user has entered so far
var value = AFMergeChange(event);
// Do nothing if there are no characters
if(!value) return;
//If user attempts to enter anything other than E or M, reject it
if(!AFExactMatch(/[E]|[M]{0,1}/, value)) event.rc = false;
}
Now, as the custom keystroke script for each field that you want to do this for, use the following:
if (!event.willCommit) EorM_ks();
George